I'm getting a Laravel error when trying to clear the routes cache: Unable to prepare route [login] for serialization. Another route has already been assigned name [auth.login]. I have two auth routes:
Route::get('login', [LoginController::class, 'showLoginForm'])->name('auth.login')->middleware('web');
Route::post('login', [AuthController::class, 'authenticate'])->name('auth.login');
I know the error is there because there are two routes with the same name. But if I remove the name from the POST route, when I go to the login screen URL, I get a 405 Method not allowed error. This is very strange, because the POST route is only used when I type the credentials and click the Login button, not when I go to the login screen URL. Everything works fine with the same names in both routes, but that doesn't make sense.
showLoginForm method is a default method. authenticate method is a custom method:
public function authenticate(Request $request) {
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
$user = User::where('email', $request->email)->firstOrFail();
session()->regenerate();
$user = Auth::user();
if (session('saved') == null) {
Session::put('email', $request->email);
Session::put('password', $request->password);
}
return redirect()->intended(route('home'));
}
return back()->withErrors([
'email' => 'The provided credentials do not match our records.',
]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire