F
Filamentβ€’2y ago
benshawuk

Correct way to add additional middleware route groups

I have managed to get Jetstream's "EmailVerified" functionality working with Filament by wrapping the resource and pages route groups around it in vendor/filament/filament/routes/web.php :
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::middleware(config('filament.middleware.auth'))->group(function (): void {
Route::name('pages.')->group(function (): void {
foreach (Filament::getPages() as $page) {
Route::group([], $page::getRoutes());
}
});

Route::name('resources.')->group(function (): void {
foreach (Filament::getResources() as $resource) {
Route::group([], $resource::getRoutes());
}
});
});
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::middleware(config('filament.middleware.auth'))->group(function (): void {
Route::name('pages.')->group(function (): void {
foreach (Filament::getPages() as $page) {
Route::group([], $page::getRoutes());
}
});

Route::name('resources.')->group(function (): void {
foreach (Filament::getResources() as $resource) {
Route::group([], $resource::getRoutes());
}
});
});
Obviously this isn't ideal, nor would be publishing the routes file (if that's even possible). Is there a way I can achieve the same result by adding to the middleware section of the Filament config? Or some other place? If so, what would be the syntax for this? If I try and add the middleware route groups in my main web.php, it doesn't respect/know about the Filament ones.
2 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Is there a way I can achieve the same result by adding to the middleware section of the Filament config?
I think this is probably the way to go I believe 'verified' corresponds to Illuminate\Auth\Middleware\EnsureEmailIsVerified
benshawuk
benshawukOPβ€’2y ago
Yes! That works perfectly. Thanks! You're a superstar, @pboivin ! πŸ˜„
Want results from more Discord servers?
Add your server