Laravel-adminlte: QUESTION: Menu with 'can' => 'manage-blog',

Created on 21 May 2018  路  5Comments  路  Source: jeroennoten/Laravel-AdminLTE

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 ???

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

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.

All 5 comments

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.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.

thanks @arifulhp your solution worked on Laravel 5.5

Dude, thank you very much!!!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iHeartBard picture iHeartBard  路  4Comments

niltonssjr picture niltonssjr  路  4Comments

ahishamali10 picture ahishamali10  路  5Comments

WillieOng-HK picture WillieOng-HK  路  4Comments

dunfy picture dunfy  路  6Comments