mirror of
https://github.com/flarum/framework.git
synced 2024-11-27 19:13:37 +08:00
Add 'hasPermission' helper to Group (#1688)
* Add Group@hasPermission helper * Improve performance of method
This commit is contained in:
parent
67f9375d47
commit
9684fbc4da
|
@ -126,4 +126,19 @@ class Group extends AbstractModel
|
|||
{
|
||||
return $this->hasMany(Permission::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the group has a certain permission.
|
||||
*
|
||||
* @param string $permission
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPermission($permission)
|
||||
{
|
||||
if ($this->id == self::ADMINISTRATOR_ID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->permissions->contains('permission', $permission);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user