/** * Get allowed roles for the current user. * * @return mixed */ protected function getAllowedRoles() { if ($this->request->user('administrator')->isRole('super-administrator')) { $roles = $this->role->get(); } else { $roles = $this->role->where('slug', '!=', 'super-administrator')->get(); } return $roles; }
/** * Can at least blade directive compiler. * * @param string|array $permissions * @return bool * @throws \Exception * @throws \Throwable */ public function handle($permissions) { if (auth()->check()) { return auth()->user()->canAtLeast((array) $permissions); } else { $guest = Role::whereSlug('guest')->first(); if ($guest) { return $guest->canAtLeast((array) $permissions); } } return false; }
/** * Attach a role to user using slug. * * @param $slug * @return bool */ public function attachRoleBySlug($slug) { $role = Role::where('slug', $slug)->first(); return $this->attachRole($role); }
/** * Remove selected role. * * @param \Yajra\Acl\Models\Role $role * @return \Illuminate\Http\RedirectResponse */ public function destroy(Role $role) { if (!$role->system) { try { $role->delete(); return $this->notifySuccess('Role successfully deleted!'); } catch (QueryException $e) { return $this->notifyError($e->getMessage()); } } return $this->notifyError('Role is protected and cannot be deleted!'); }
/** * Register ACL models cache listener. */ protected function registerCacheListener() { Permission::saved(function () { $this->app['cache.store']->forget('permissions.policies'); }); Permission::deleted(function () { $this->app['cache.store']->forget('permissions.policies'); }); Role::saved(function () { $this->app['cache.store']->forget('permissions.policies'); }); Role::deleted(function () { $this->app['cache.store']->forget('permissions.policies'); }); }
/** * Show and edit selected permission. * * @param \Yajra\Acl\Models\Permission $permission * @return \Illuminate\View\View */ public function edit(Permission $permission) { $roles = Role::all(); return view('administrator.permissions.edit', compact('permission', 'roles')); }
/** * @return \Illuminate\Database\Eloquent\Builder */ public function query() { return Role::query(); }