Handle access dashboard with laravel and entrust

53 Views Asked by At

I tried using entrust package and works well. I have different types of roles assign to different users. The users are have roles access to dashboard to do according to their permission. I need to make middleware on routes using entrust package to check user has last one role and permission before access the dashboard. or if there other best performance/solution to do this.

1

There are 1 best solutions below

1
On

Entrust has its own middleware,

'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,

You just need to register them in App\Http\Kernel.php. In your routes\web.php create a group with a middleware for specific users:

Route::group(['middleware'=> 'role'], function({
   Route::get('/somelink', 'SomeController@somefunction');
});