Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] link() helper on CrudColumn #5317

Merged
merged 14 commits into from
Oct 31, 2023
23 changes: 23 additions & 0 deletions src/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@
});
}

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'])) {
pxpm marked this conversation as resolved.
Show resolved Hide resolved
$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']);
pxpm marked this conversation as resolved.
Show resolved Hide resolved
};
}

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