Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
karandatwani92 committed Sep 13, 2023
1 parent 4cd8e5d commit 23db134
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 23db134

Please sign in to comment.