/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $model = Authorization::permission();
     $label = $this->argument('label');
     $name = str_slug($label);
     $exists = $model->whereName($name)->first();
     if (!$exists) {
         $model::forceCreate(['name' => $name, 'label' => $label]);
         $this->info("Successfully created permission: {$name}.");
     } else {
         $this->error("A permission named {$name} already exists.");
     }
 }
 /**
  * A role may be given various permissions.
  *
  * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  */
 public function permissions()
 {
     $model = get_class(Authorization::permission());
     return $this->belongsToMany($model);
 }
 public function test_permission_helper()
 {
     config()->set('authorization.permission', Permission::class);
     $this->assertInstanceOf(Permission::class, Authorization::permission());
 }
 /**
  * Returns a new permission model instance.
  *
  * @return \Illuminate\Database\Eloquent\Model|null
  */
 protected function getPermissionsModel()
 {
     return Authorization::permission();
 }
 /**
  * Determine if the user may perform the given permission.
  *
  * @param string|Model $permission
  *
  * @return bool
  */
 public function hasPermission($permission)
 {
     if (is_string($permission)) {
         // If we weren't given a permission model, we'll try to find it by name.
         $permission = Authorization::permission()->whereName($permission)->first();
     }
     if ($this->permissions->contains($permission)) {
         return true;
     }
     if ($permission instanceof Model) {
         $roles = $permission->roles;
         foreach ($roles as $role) {
             if ($this->hasRole($role)) {
                 return true;
             }
         }
     }
     return false;
 }