It took me a bit to find this answer so hopefully I’m saving you time. As described in the Laravel Authentication docs go to bootstrap/app.php
and add the following to your Middleware
.
$middleware->redirectGuestsTo('/login');
Which should leave app.php
looking like this in a brand new install.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// redirect users that are NOT logged in to this URL
$middleware->redirectGuestsTo('/login');
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Change /login
to whatever URL you want to send guests to.