예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
 /**
  * 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!');
 }
예제 #5
0
 /**
  * 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');
     });
 }
예제 #6
0
 /**
  * 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'));
 }
예제 #7
0
 /**
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function query()
 {
     return Role::query();
 }