mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Add 'hasPermission' helper to Group (#1688)
* Add Group@hasPermission helper * Improve performance of method
This commit is contained in:
committed by
Franz Liedke
parent
7ffca76c61
commit
6d185eecf1
@@ -126,4 +126,19 @@ class Group extends AbstractModel
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Permission::class);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user