How To Make Sure User Email is Verified Before Using The App
Sometimes, you might want to ensure that users have verified their email addresses before they can access certain parts of your application. This is a common requirement for many applications to prevent spam and ensure that users are legitimate.
To enforce email verification, you can use the verified
middleware provided by Laravel. This middleware checks if the authenticated user has a verified email address.
Protecting Routes with Email Verificationโ
You can apply the verified
middleware to your routes or controllers. For example, if you want to protect a page, you can do it like this:
In the routes/web.php
file, you can add the middleware to a specific route:
Route::get('/protected-page', [ProtectedController::class, 'index'])
->middleware('verified') // <-- This ensures the user has a verified email
->name('protected.page');
If the user did not verify their email, they will be redirected to the email verification notice page.

Protecting Customer Dashboard (Filament)โ
If you want to protect the entire customer dashboard, you can add the Illuminate\Auth\Middleware\EnsureEmailIsVerified
middleware to the middleware array in the app/Providers/Filament/DashboardPanelProvider.php
(Dashboard Panel Provider) file:
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
public function panel(Panel $panel): Panel
{
return $panel
// ... other configurations
->middleware([
// ... other middlewares
EnsureEmailIsVerified::class, // <-- This ensures the user has a verified email
]);
}