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 67f9375d47
commit 9684fbc4da

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