I'm trying to show the menu just according to the type of user. I have how to do this in other ways, but I would use type reported in the project, using CAN. Someone has a practical example to show me how I should do this. Have I read the documentation several times and can not get a positive result ???
I was looking for a solution as it wasn't working in my code also. I was using Policy files but Laravel-AdminLTE documentation mention of Gate
This integrates with Laravel's Gate functionality.
So I decided to write a gate for menu only. I added this code in AuthServiceProvider.php
```
public function boot()
{
$this->registerPolicies();
Gate::define('browse-teacher', function ($user) {
if ($user->role == 'admin'){
return true;
}
return false;
});
}
```
My menu is:
[
'text' => 'lms.menu.teachers',
'url' => 'admin/teachers',
'icon' => 'users',
'can' => 'browse-teacher',
],
And it work fine :)
I guess its a limitation that it doesn't work with Policy but only gates for the menu is fine with me.
Thank's very much @arifulhb ,
I will test !
Much obliged !
@arifulhb
Hi, I tested your solution but it does not work for me
I was looking for a solution as it wasn't working in my code also. I was using Policy files but Laravel-AdminLTE documentation mention of Gate
This integrates with Laravel's Gate functionality.
So I decided to write a gate for menu only. I added this code in
AuthServiceProvider.phppublic function boot() { $this->registerPolicies(); Gate::define('browse-teacher', function ($user) { if ($user->role == 'admin'){ return true; } return false; }); }My menu is:
[ 'text' => 'lms.menu.teachers', 'url' => 'admin/teachers', 'icon' => 'users', 'can' => 'browse-teacher', ],And it work fine :)
I guess its a limitation that it doesn't work with Policy but only gates for the menu is fine with me.
thanks @arifulhp your solution worked on Laravel 5.5
Dude, thank you very much!!!!!
Most helpful comment
I was looking for a solution as it wasn't working in my code also. I was using Policy files but Laravel-AdminLTE documentation mention of Gate
So I decided to write a gate for menu only. I added this code in
AuthServiceProvider.php```
public function boot()
{
$this->registerPolicies();
```
My menu is:
And it work fine :)
I guess its a limitation that it doesn't work with Policy but only gates for the menu is fine with me.