validate([ 'email' => ['required', 'email'], 'password' => ['required'] ]); if (Auth::attempt($creds)) { $request->session()->regenerate(); return redirect()->intended(); } return back()->withErrors([ 'The provided credentials do not match our records.' ]); } public function register(Request $request) { Auth::logout(); $creds = $request->validate([ 'email' => ['required', 'email', 'unique:users'], 'name' => ['required', 'unique:users'], 'password' => ['required'] ]); $creds["password"] = Hash::make($creds["password"]); User::create($creds); return redirect("login")->withSuccess("Success! Now login"); } public function logout(Request $request) { Auth::logout(); $request->session()->invalidate(); $request->session()->regenerate(); return back(); } public function view() { return view("login", []); } }