I created a custom authentication for my Laravel app following that tutorial: https://medium.com/@nasrulhazim/laravel-using-different-table-and-guard-for-login-bc426d067901
I adapted it to my needs but I didn't have to change much.
In the end, when I try to go the the /home route, but it says: "Route [login] not defined."
My guess is that a default behavior of the authentication call the login route instead of the /fidelite/login I've created.
Here is my provider:
fidelite' => [
'driver' => 'eloquent',
'model' => App\Fidelite::class,
],
And the guard
'fidelite' => [
'redirectTo' => 'fidelite.home',
'driver' => 'session',
'provider' => 'fidelite',
],
The routes defined in the web.php file
Route::prefix('fidelite')
->as('fidelite.')
->group(function() {
Route::get('/home', 'Home\FideliteHomeController@index')->name('home');
Route::namespace('Auth\Login')
->group(function() {
Route::get('login', 'FideliteController@showLoginForm')->name('login');
Route::post('login', 'FideliteController@login')->name('login');
Route::post('logout', 'FideliteController@logout')->name('logout');
Route::get('register', 'FideliteController@showRegisterForm')->name('register');
});
});
Basically, there is two controllers; the first one, FideliteController adds the middleware and show the needed forms to login / register
class FideliteController extends DefaultLoginController
{
protected $redirectTo = '/fidelite/home';
public function __construct()
{
$this->middleware('guest:fidelite')->except('logout');
}
public function showLoginForm()
{
return view('auth.login.fidelite');
}
public function showRegisterForm()
{
return view('auth.compte');
}
public function username()
{
return 'email';
}
protected function guard()
{
return Auth::guard('fidelite');
}
}
And the other one returns the /fidelite/home page when the user is logged
class FideliteHomeController extends Controller
{
public function __construct()
{
$this->middleware('auth:fidelite');
}
public function index()
{
return view('home.fidelite');
}
}
There is something I missing, but what ?
Many thanks for your help and time...
login
route has namefidelite.login
because of the groupas
and has duplicate namesfidelite.login
. – The Alpharoute('login')
to generate the login link. – The AlphaFideliteHomeController ::constructor
by$this->middleware('auth:fidelite');
it may have used any redirection of login. – The Alphareturn view('home.fidelite');
in the index function byreturn 'hello';
, the same error occurs – Laurent Kreps