Sunday, April 9, 2017

Laravel authorization using middleware

I have following tables:

Role Table

  1. ID
  2. Title

Permission Table

  1. ID
  2. Title
  3. Role_id
  4. Permissions ( like : {test:"create","edit","update","delete"} )

Now after logging in how can I check through middleware whether that specific user has above permissions, whether he can create/edit/update/delete.

I don't want to specify the permissions or role name in routes.

Route::group(['permission'=>'create-user'] ...

Instead want to check with the help of middleware.

Route::group(['middleware'=>'authorization'] ...

So that I don't have to specify individual permissions in route each time new role and permissions to those role has been added.

Thankyou



via nasor

Advertisement