public function create(array $data)
 {
     $user = $this->model->create($data);
     $permissions = Permission::$defaultPermissions;
     $user->setRole(Role::$defaultRole);
     foreach ($permissions as $permission) {
         $user->attachPermission($permission);
     }
     return $user;
 }
 public function update(User $user, Request $request)
 {
     $this->validate($request, $user->getUpdateRules());
     $data = $request->only('name', 'email');
     if ($request->has('password')) {
         $data['password'] = $request->input('password');
     }
     if ($user->fill($data)->save()) {
         \Flash::success('Profile successfully updated!');
     }
     return redirect()->back();
 }
 public function run()
 {
     \DB::table('user_role')->truncate();
     $usersRoles = [['user_id' => \App\Clusters\AuthCluster\Models\User::where('username', '=', 'admin')->firstOrFail()->id, 'role_id' => \App\Clusters\AuthCluster\Models\AccessControl\Role::where('name', '=', 'admin')->firstOrFail()->id], ['user_id' => \App\Clusters\AuthCluster\Models\User::where('username', '=', 'user')->firstOrFail()->id, 'role_id' => \App\Clusters\AuthCluster\Models\AccessControl\Role::where('name', '=', 'user')->firstOrFail()->id]];
     foreach ($usersRoles as $permission) {
         \App\Clusters\AuthCluster\Models\AccessControl\UserRole::create($permission);
     }
 }
 public function it_deletes_permissions_when_setting_a_role(FunctionalTester $I)
 {
     $user = User::where('username', '=', 'admin')->firstOrFail();
     $I->seeRecord($this->URT, ['user_id' => $user->id]);
     $I->seeRecord($this->UPT, ['user_id' => $user->id]);
     $user->setRole('user');
     $I->dontSeeRecord($this->UPT, ['user_id' => $user->id]);
 }
 public function run()
 {
     \DB::table('user_permission')->truncate();
     $adminUserID = \App\Clusters\AuthCluster\Models\User::where('username', '=', 'admin')->firstOrFail()->id;
     $usersRolesPermissions = [['user_id' => $adminUserID, 'permission_id' => '1'], ['user_id' => $adminUserID, 'permission_id' => '2'], ['user_id' => $adminUserID, 'permission_id' => '3']];
     foreach ($usersRolesPermissions as $permission) {
         \App\Clusters\AuthCluster\Models\AccessControl\UserPermission::create($permission);
     }
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot(Router $router)
 {
     if (!$this->app->routesAreCached()) {
         require realpath(base_path('app/Clusters/AuthCluster/Resources/auth_cluster_routes.php'));
     }
     $router->bind('userName', function ($username) {
         return \App\Clusters\AuthCluster\Models\User::whereUsername($username)->firstOrFail();
     });
 }
 public function destroy($id)
 {
     $user = User::findOrFail($id);
     $userRolePermissions = $user->permissionsRelation();
     $userRole = $user->roleRelation();
     $msg = 'User successfully deleted';
     if ($userRolePermissions && $userRolePermissions->delete()) {
         $msg .= ', with user permissions';
     }
     if ($userRole && $userRole->delete()) {
         $msg .= ', with user role';
     }
     if (!$user->delete()) {
         Flash::error('There was and error deleting the user!');
     }
     Flash::success($msg . '.');
     return redirect()->back();
 }