'Laravel 9: Custom login
I am trying to change the default table that laravel 9 uses to authenticate the users.
But while I can see that user is authenticanted in the login function of LoginController
when I try to redirect to home page as logged in user I get the error
Route [login] not defined.
If the user is logged in why does it try to redirect to login
route and not to home
Here is my LoginController.php
public function login(LoginRequest $request)
{
$credentials = $request->getCredentials();
/*
if(!Auth::validate($credentials)):
return redirect()->to('login')
->withErrors(trans('auth.failed'));
endif;
*/
$user = Auth::getProvider()->retrieveByCredentials($credentials);
if(empty($user)){
return redirect()->to('login')
->withErrors(trans('auth.failed'));
}
Auth::login($user);
//Auth::check() returns true here!
return $this->authenticated($request, $user);
}
/**
* Handle response after user authenticated
*
* @param Request $request
* @param Auth $user
*
* @return \Illuminate\Http\Response
*/
protected function authenticated(Request $request, $user)
{
return redirect()->intended('/home');
}
and here are my routes in web.php
Route::group(['namespace' => 'App\Http\Controllers'], function()
{
Route::group(['middleware' => ['guest']], function() {
/**
* Register Routes
*/
Route::get('/register', 'RegisterController@show')->name('register.show');
Route::post('/register', 'RegisterController@register')->name('register.perform');
/**
* Login Routes
*/
Route::get('/login', 'LoginController@show')->name('login.show');
Route::post('/login', 'LoginController@login')->name('login.perform');
});
Route::group(['middleware' => ['auth']], function() {
Route::get('/home', 'HomeController@index')->name('home.index');
/**
* Logout Routes
*/
Route::get('/logout', 'LogoutController@perform')->name('logout.perform');
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|