Mar 25, 2022
0
Level 7
How to implement Laravel Fallback Routes with Laravel Nova?
For a project we're working on right now, we have requirements to serve a couple wildcard routes from the root domain, which is a little frustrating, but I am wondering if anyone has experience with fallback routes and how to implement them?
Here is a shortened version of my routes web.php file:
/**
* This group middleware is to ensure that users
* have a zip code in their session.
* If they don't, they are redirected to the zip code lookup page.
* If they do, they are redirected to the next route.
*
*/
Route::middleware([CheckBrandSessionMiddleware::class])
->group(function () {
/**
* Get list of news articles for a brand.
*/
Route::get('{brand}/news', [ArticlesController::class, 'index'])
->name('articles.index');
/**
* Get a dispute for a brand.
* (This must come after the news route, as this is a wildcard catch-all route.)
*/
Route::get('{brand}/{dispute}', [DisputeController::class, 'show'])
->name('disputes.show');
/**
* This is here to ensure that requests to admin routes are accessible
* since we are using wildcard routes to generate routes to a brands pages.
*
* We also need to ensure that this is the last route in the routes file as this will override
* all other routes hereafter.
*/
Route::get('/{brand}', [BrandController::class, 'show'])
->name('brands.show');
});
Route::fallback(function ($request) {
return "test"; // Fallback route that I want to implement. This does nothing and the 404 page is still being returned.
});
Please or to participate in this conversation.