validate([ 'username' => 'required|max:64', 'password' => 'required' ]); if(Auth::attempt($credentials)) { $request->session()->regenerate(); return redirect("/"); } return view("error"); } public function registerView() { return view('register'); } public function register(Request $request) { $rawUser = $request->validate([ 'name' => 'required|max:64|min:2', 'password' => 'required|max:48|min:8|confirmed', 'username' => 'required' ]); $user = new User($rawUser); $user->password = Hash::make($user->password); $user->role()->associate(Role::where('name', 'User')->first()); if($user->save()) { return redirect("login"); } return redirect("error"); } public function logout() { Auth::logout(); return redirect("/"); } }