Applying auth middleware to all laravel routes

Route::group(['middleware' => ['auth']], function () { 
    Route::get('/users', [UsersController::class,'admin'])->name('users.admin');
    Route::post('/users/search', [UsersController::class,'inactive'])->name('users.admin.search');
    Route::get('/users/inactive', [UsersController::class,'inactive'])->name('users.admin.inactive');
});


In route group we can set auth into middleware which will put all the defined routes under this auth middleware.

That means any visitor who will try to visit those routes will be redirected to login page. Only logged in users will be able to access those routes.

Related Posts