/**
  * @param $command
  *
  * @return mixed
  */
 public function execute($command)
 {
     if (isset($command->userId)) {
         \Cache::forget('user_capabilities_' . $command->userId);
     }
     if (isset($command->roleId)) {
         $role = Role::with('users')->findOrFail($command->roleId);
         foreach ($role->users as $user) {
             \Cache::forget('user_capabilities_' . $user->id);
         }
     }
     return true;
 }
 private function tableSeed()
 {
     $allUsers = User::all();
     $adminUsers = User::where('username', 'LIKE', '%2%')->get();
     $staffUsers = User::where('username', 'NOT LIKE', '%2%')->get();
     foreach ($adminUsers as $user) {
         $user->roles()->sync([Role::whereName('admin')->first()->id]);
     }
     foreach ($staffUsers as $user) {
         $user->roles()->sync([Role::whereName('staff')->first()->id]);
     }
     foreach ($allUsers as $user) {
         $user->roles()->attach(Role::whereName('user')->first()->id);
     }
 }
 private function tableSeed()
 {
     $adminCapabilities = Capability::all();
     $userCapabilities = Capability::whereIn('name', ['login', 'logout', 'access_admin_dashboard'])->get();
     $staffCapabilities = Capability::whereIn('name', ['login', 'logout', 'access_admin_dashboard', 'update_user_profile', 'update_user_password'])->get();
     $admins = Role::whereName('admin')->get();
     $staff = Role::whereName('staff')->get();
     $users = Role::whereName('user')->get();
     foreach ($admins as $admin) {
         $admin->capabilities()->sync($adminCapabilities->lists('id'));
     }
     foreach ($staff as $staff) {
         $staff->capabilities()->sync($staffCapabilities->lists('id'));
     }
     foreach ($users as $user) {
         $user->capabilities()->sync($userCapabilities->lists('id'));
     }
 }
 /**
  * @param $userId
  *
  * @return mixed
  */
 public function edit($userId)
 {
     $user = $this->repository->showUser($userId);
     $roles = Role::all();
     $user->roles = $user->roles->lists('id');
     $breadcrumb = new Breadcrumb($this->breadcrumbConfig, ['user_id' => $userId]);
     return View::make('users.edit', compact('user', 'roles', 'breadcrumb'));
 }
 /**
  * handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $role = Role::updateRights($command->roleId, $command->name, $command->capabilities);
     $this->dispatchEventsFor($role);
     return $role;
 }
 /**
  * handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $role = Role::deleteRole($command->roleId);
     $this->dispatchEventsFor($role);
     return $role;
 }
 /**
  * Return a single role model based on the given role id
  *
  * @param $roleId
  * @param array $with
  *
  * @return null
  */
 public function getRole($roleId, $with = [])
 {
     return Role::with($with)->find($roleId);
 }
 /**
  * handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $role = Role::createNewRole($command->name, $command->capabilities);
     $this->dispatchEventsFor($role);
     return $role;
 }
 /**
  * Get the list of all roles available
  */
 private function listAllRoles()
 {
     $this->rolesList = Role::distinct()->get(['name'])->lists('name', 'name');
 }
Ejemplo n.º 10
0
 /**
  * @param $userId
  * @param $roleIds
  *
  * @return mixed
  */
 public static function updateRoles($userId, $roleIds)
 {
     $user = self::findOrFail($userId);
     $defaultRoleId = [Role::whereName('user')->first()->id];
     $user->roles()->sync(array_merge($roleIds, $defaultRoleId));
     $user->raise(new UserRolesWereUpdated($user));
     return $user;
 }
 /**
  * @param $faker
  */
 private function seedTable($faker)
 {
     Role::create(['name' => 'admin']);
     Role::create(['name' => 'staff']);
     Role::create(['name' => 'user']);
 }