Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Providers;
  4.  
  5. use App\Farmer\Models\Permission;
  6. use App\Farmer\Models\User;
  7. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  8.  
  9. class AuthServiceProvider extends ServiceProvider
  10. {
  11.     /**
  12.      * The policy mappings for the application.
  13.      *
  14.      * @var array
  15.      */
  16.     protected $policies = [
  17.         'App\Model' => 'App\Policies\ModelPolicy',
  18.     ];
  19.  
  20.     /**
  21.      * Register any authentication / authorization services.
  22.      */
  23.     public function boot()
  24.     {
  25.         $this->registerPolicies();
  26.  
  27.         if (\App::runningInConsole()) {
  28.             return;
  29.         }
  30.  
  31.         foreach ($this->getPermissions() as $permission) {
  32.             \Gate::define($permission->name, function (User $user) use ($permission) {
  33.                 return $user->hasRole($permission->roles);
  34.             });
  35.         }
  36.     }
  37.  
  38.     protected function getPermissions()
  39.     {
  40.         return Permission::with('roles')->get();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement