/** * Create a new user instance after a valid registration. * * @param array $data * @return \Illuminate\Http\RedirectResponse */ protected function create(array $data) { try { $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); $user->roles()->attach($data['roles']); $user->save(); flash()->success('Usuário ' . $data['name'] . ' adicionado com sucesso!'); return redirect()->route('usuarios.index'); } catch (ModelNotFoundException $e) { flash()->error('Desculpe, erro ao salvar usuário'); return redirect()->route('usuarios.index'); } }
/** * Run the database seeds. * * @return void */ public function run() { User::truncate(); User::create(['name' => 'Administrador Master', 'email' => '*****@*****.**', 'password' => Hash::make('s@wil123#'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); DB::table('role_user')->insert(['user_id' => User::where('email', '=', '*****@*****.**')->first()->id, 'role_id' => Role::where('role_slug', '=', 'role_master')->first()->id]); }