Skip to main content

Multiple guards

By default everything runs through the configured guard. To let a request sign in to another guard — say an admin guard alongside web — list it in guards and submit a guard field from your sign-in form:

'guard' => 'web',
'guards' => ['admin'],
<input type="hidden" name="guard" value="admin">

The request issues the token for the selected guard, the user is resolved through that guard's user provider, and login completes on it. A guard not on the allowlist falls back silently to the default, so guards stay un-enumerable.

The security rule​

Only list guards whose user provider you are happy to expose to self-service magic-link login. A user found in a guard's provider can sign in to that guard, so guards that share a provider also share access.

When the Fortify two-factor handoff is active, the selected guard should match fortify.guard — Fortify re-resolves the challenged user from its own guard's provider, and mismatched providers make the challenge fail closed.

A guard per host​

The guard field lets every request pick any guard in guards, on every host. When the guard should follow the host instead, the readers of a site on the site's host and the team on the application's host, name a GuardResolver of your own in guard_resolver. It decides when a link or a code is issued and again when one is redeemed, and the field changes nothing it does not read itself. Choose the guard by host has the example.

Minting for a specific guard​

The Mint API takes the guard as its second argument:

$link = $issuer->issueLink($user, 'admin');

The guard must be the default or one of the allowlisted guards, and the user must resolve through that guard's provider — otherwise you get an UnknownGuardException or a UserNotInGuardException rather than a credential that could never be consumed. With a guard_resolver, a minted link opens a session only on a request the resolver gives its guard.