0
People created this group of routes for certain pages of my project to be protected by middleware auth:
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'as' => 'admin.'], function () {
Route::get('/', [AuthController::class, 'loginPage'])->name('login');
Route::group(['middleware' => 'auth'], function () {
Route::get('home', [AuthController::class, 'home'])->name('home');
});
});
But when I check the list of routes the middleware was not applied to the route home:
Does anyone know what might be going wrong?
And this would be the best way to make this process?
In the route print there is the middleware auth. I don’t understand. Open an anonymous browser session and try to access the home route, if ok, you should not load the home route/view page See another way to use middleware groups here https://laravel.com/docs/8x/middleware#middleware-groups
– Marcos Xavier
The way you protected the route is correct. Also, from what I saw in the screeshot, the middleware is being applied. Have you checked if you can access without logging in? Try logging out or accessing.
– Thiago Maciel