From 23db1343ac4236cce999f18baedd4262bbad8e79 Mon Sep 17 00:00:00 2001 From: Karan Datwani Date: Wed, 13 Sep 2023 22:19:33 +0530 Subject: [PATCH] init --- src/macros.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/macros.php b/src/macros.php index 5f4ce9564d..14c562f5f1 100644 --- a/src/macros.php +++ b/src/macros.php @@ -52,6 +52,28 @@ }); } +if (!CrudColumn::hasMacro('linkTo')) { + CrudColumn::macro('linkTo', function ($route, $target = null) { + + $wrapper = $this->attributes['wrapper'] ?? []; + if (in_array($this->attributes['type'], ['select','select_grouped','select2','select2_grouped','select2_nested','select2_from_ajax'])) { + $wrapper['href'] = function ($crud, $column, $entry, $related_key) use ($route) { + return route($route, $related_key); + }; + } else { + $wrapper['href'] = function ($crud,$column,$entry) use ($route) { + return url($route.$column["value"]); + }; + } + + if ($target) + $wrapper['target'] = $target; + + $this->wrapper($wrapper); + return $this; + }); +} + /** * The route macro allows developers to generate the routes for a CrudController, * for all operations, using a simple syntax: Route::crud().