Skip to main content
Version: 2.x

Middlewares

Authentication Middleware

The f.auth can be used to only allow authenticated users to access a given route. It ensures that the user session is authenticated, redirecting to the login page if necessary. Additionally, it sets cache control headers to prevent caching of sensitive data. Since this middleware is already registered in your application, all you need to do is attach the middleware to a route definition:

Route::get('/profile', function () {
// Only authenticated users may access this route...
})->middleware('f.auth');
info

To change the route which a user is redirected to when already authenticated, See here.

Unauthentication Middleware

The f.guest can be used to only allow unauthenticated users to access a given route.

Route::get('/login', function () {
// Only unauthenticated users may access this route...
})->middleware('f.guest');
info

To change the route which a user is redirected to when not authenticated, See here.