From 9684fbc4da07d32aa322d9228302a23418412cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Mon, 10 Dec 2018 16:32:21 -0500 Subject: [PATCH] Add 'hasPermission' helper to Group (#1688) * Add Group@hasPermission helper * Improve performance of method --- src/Group/Group.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Group/Group.php b/src/Group/Group.php index 103dd4fea..bed5fd7dc 100644 --- a/src/Group/Group.php +++ b/src/Group/Group.php @@ -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); + } }