+ return $this->roles->pluck('name')->contains($role);
+ }
+
+ /**
+ * Check if the user has a role.
+ * @param $role
+ * @return mixed
+ */
+ public function hasSystemRole($role)
+ {
+ return $this->roles->pluck('system_name')->contains($role);
+ }
+
+ /**
+ * Get all permissions belonging to a the current user.
+ * @param bool $cache
+ * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
+ */
+ public function permissions($cache = true)
+ {
+ if (isset($this->permissions) && $cache) {
+ return $this->permissions;
+ }
+ $this->load('roles.permissions');
+ $permissions = $this->roles->map(function ($role) {
+ return $role->permissions;
+ })->flatten()->unique();
+ $this->permissions = $permissions;
+ return $permissions;