예제 #1
0
 /**
  * Determines if a role has access to given permission.
  *
  * @param $identifier
  * @return bool
  * @throws \Krucas\RBAuth\Implementations\Eloquent\Exceptions\AccessNotFoundException
  */
 public function can($identifier)
 {
     $permission = Permission::where('permission', $identifier)->first();
     if ($permission) {
         $access = $this->access()->where('permission_id', $permission->id)->first();
         if (!$access) {
             throw new AccessNotFoundException();
         } else {
             return $access->isEnabled();
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Determines if a user has access to given permission.
  *
  * @param $identifier
  * @return bool
  */
 public function can($identifier)
 {
     $permission = Permission::where('permission', $identifier)->first();
     if ($permission) {
         $access = $this->access()->where('permission_id', $permission->id)->first();
         if ($access) {
             return $access->isEnabled();
         }
     }
     foreach ($this->getRoles() as $role) {
         try {
             return $role->can($identifier);
         } catch (AccessNotFoundException $ex) {
             // Handle this as you want.
         }
     }
     return false;
 }