I am currently using https://github.com/jeroennoten/Laravel-AdminLTE for my laravel project. The problem I am facing is that I am trying to pass a parameter to the can method in the menu configuration as seen below but haven't gotten any luck to get it to work.
Menu Config:
[
'text' => 'Add new post',
'url' => 'admin/blog/new',
'can' => ['access:posts'],
],
The posts gate:
Gate::define('access', function ($user,$location) {
return $user->hasAccess($location);
});
I think i might be passing the parameter to the gate incorrectly.
You can't pass additional argument.
But if you just want to bypass variable you can do using use
. An example you can define based URL segment/path.
$location = request()->segment(1); // get 'blog' from admin/blog/new
Gate::define('access', function ($user) use($location) {
return $user->hasAccess($location);
});