In Laravel 11, the Auth middleware is located in the vendor folder. I'm utilizing it for my authentication routes:
Route::prefix('account')->group(function () {
Route::middleware(['auth'])->group(function () {
Route::get('/', [AccountController::class, 'dashboard'])->name('account.dashboard');
});
Route::middleware(['guest'])->group(function () {
Route::get('/login', [AccountController::class, 'login'])->name('account.login');
Route::post('/authenticate', [AccountController::class, 'authenticate'])->name('account.authenticate');
Route::get('/register', [AccountController::class, 'register'])->name('account.register');
Route::post('/signup', [AccountController::class, 'signup'])->name('account.signup');
});
});
When I try to access an auth route, such as account.dashboard, without being logged in, I want to be redirected to account.login instead of the default login route. How can I modify the Auth middleware logic to achieve this? Additionally, how can I make the same adjustment for the guest middleware?