Auth or Guest or both, middleware. While watching Laravel from scratch 5.7, question arose about auth and guest middleware.
Can I authenticate multiple routes so I can apply Auth middleware just once in the codebase?
Route groups:
Route::group(['middleware' => ['auth']], function () {
// routes that require user to be authenticated
});
You might also see the middleware applied as a method (same result, different syntax):
Route::middleware(['auth'])->group(function () {
// routes that require user to be authenticated
});
Okay so groups are a way to go.
Thank you!
I'd really suggest giving the docs a thorough reading through: https://laravel.com/docs/5.7/routing
You're only going to learn a certain % of the capabilities by watching the videos, which are a great supplement to the actual docs.
Exactly. You can define routes for both guest and non-authenticated users outside that group; or indeed have a route group for guests only (e.g. register, login):
Route::middleware(['guest'])->group(function () {
// routes that require user to be authenticated
});
when we use auth and guest , or they are the same ?
Please sign in or create an account to participate in this conversation.