Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Customising The fallbackPlaceholder In Laravels Fallback Route

There is a neat feature in Laravel called a Fallback Route. This is the route which will handle the request if none of the others can:

Route::fallback(Controller::class);

The fallback method is simply a convenience function which expands to the following:

Route::get('{fallbackPlaceholder}', Controller::class)
    ->where('fallbackPlaceholder', '.*')
    ->fallback();

Knowning this we can easily rename the fallbackPlaceholder parameter by defining our own route and chaining the fallback() method:

Route::get('{myPlaceholderName}', Controller::class)
    ->where('myPlaceholderName', '.*)
    ->fallback();


This post first appeared on Blog | Freshleaf Media, please read the originial post: here

Share the post

Customising The fallbackPlaceholder In Laravels Fallback Route

×

Subscribe to Blog | Freshleaf Media

Get updates delivered right to your inbox!

Thank you for your subscription

×