1
0
mirror of https://github.com/flarum/core.git synced 2025-07-24 18:21:33 +02:00

Add 'hasPermission' helper to Group (#1688)

* Add Group@hasPermission helper

* Improve performance of method
This commit is contained in:
David Sevilla Martín
2018-12-10 16:32:21 -05:00
committed by Franz Liedke
parent 7ffca76c61
commit 6d185eecf1

View File

@@ -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);
}
}