Skip to content

Commit

Permalink
Add 'hasPermission' helper to Group (#1688)
Browse files Browse the repository at this point in the history
* Add Group@hasPermission helper

* Improve performance of method
  • Loading branch information
David Sevilla Martín authored and franzliedke committed Dec 10, 2018
1 parent 67f9375 commit 9684fbc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,19 @@ public function permissions()
{
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);
}
}

0 comments on commit 9684fbc

Please sign in to comment.