/** * Fetch the collection of site permissions. * * @return \Illuminate\Database\Eloquent\Collection */ protected function getPermissions() { if (!Schema::hasTable('roles')) { return new Collection(); } return Permission::with('roles')->get(); }
protected function createSimplePermissions(array $permissions) { foreach ($permissions as $name => $attributes) { if (is_int($name)) { continue; } if (!is_array($attributes)) { $attributes = ['name' => $name, 'label' => $attributes]; } Permission::make($attributes)->save(); } }
/** * Constrain a roles query by the given user. * * @param \Illuminate\Database\Eloquent\Model $user * @return \Illuminate\Database\Eloquent\Builder */ protected function buildPermissionRolesQuery(Model $user) { $roles = $user->roles; return Permission::whereHas('roles', function ($query) use($roles) { return $query->whereIn('roles.id', $roles->lists('id')->all()); }); }