Laravel Gate::define easy code

Last Updated: June 4, 2020

You can us the following code define your all gates. Permission table has got the control name,action and models

Permission::get()->map(function($permission) {
 Gate::define($permission->name, function ($user) use($permission) {
   return $user->isAllowed($permission->control,$permission->action);

This code is ok for small web application. If your project is gig with several user role this code is not going to work because you have to use lots of If – else condition check whether the given user has permission to specified resource