/** * */ public function run() { /** @noinspection PhpUndefinedMethodInspection */ DB::table('role_user')->delete(); /** @noinspection PhpUndefinedMethodInspection */ DB::table('users')->delete(); /** @noinspection PhpUndefinedMethodInspection */ DB::table('roles')->delete(); $this->command->info('Vidage des tables'); $superadmin = User::create(['name' => 'superadmin', 'email' => '*****@*****.**', 'password' => bcrypt('K5XMFpS3qEiB2GD4Djn7')]); $admin = User::create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('UJqVL1amkPDkRp1S043m')]); User::create(['name' => 'user', 'email' => '*****@*****.**', 'password' => bcrypt('UtWeQ5r9gZ9gJl2lEIhK')]); $this->command->info('Creation des utilisateurs'); $superadminRole = Role::create(['name' => 'superadmin']); $adminRole = Role::create(['name' => 'admin']); $this->command->info('Creation des roles'); $superadmin->roles()->attach($superadminRole); $admin->roles()->attach($adminRole); $this->command->info('Attribution des roles'); }
/** * Mise à jour d'un utilisateur : affichage du formulaire * * @param User $user * @return \Illuminate\View\View * @throws \Exception */ public function edit(User $user) { $roles = Role::all()->lists('name', 'id'); return view('hLib.users.edit', compact('user', 'roles')); }
/** * Suppression d'un rôle * * @param Role $role * @return \Illuminate\Http\RedirectResponse */ public function destroy(Role $role) { try { $ok = $role->delete(); $flashes = $ok ? ['flash-message-success' => Lang::get('hLib.delete_ok')] : ['flash-message-danger' => Lang::get('hLib.delete_ko')]; } catch (QueryException $x) { switch ($x->getCode()) { case '23000': $flashes = ['flash-message-warning' => Lang::get('hLib.users_delete_restrict')]; break; default: $flashes = ['flash-message-danger' => Lang::get('hLib.delete_ko')]; } } catch (Exception $x) { $flashes = ['flash-message-danger' => Lang::get('hLib.delete_ko')]; } return redirect(route('roles.index'))->with($flashes); }