Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I define a default fallback route in Laravel?

I'm currently upgrading a custom CMS from Laravel 3 to Laravel 4 (this upgrade is important for various reasons).

In the existing version, it has routing set up so that routes can be individually defined--but if someone tries to load a route that is not specifically defined, the system catches it and sends it to a "page processor"--which essentially checks to see if the CMS page/post exists in the database.

The "fallback" or "default" route processing line in Laravel 3 looked like this:

Route::get('(.*)', array('uses' => 'myPageLoading@method'));

My problem is that this syntax is not supported in Laravel 4. How do I do this in Laravel 4?

like image 663
Pete Avatar asked Sep 05 '13 21:09

Pete


People also ask

What is fallback route in Laravel?

Using the Route::fallback method, you may define a route that will be executed when no other route matches the incoming request. Since you may define the fallback route within your routes/web. php file, all middleware in the web midddleware group will apply to the route.

What are the default route files in Laravel?

The Default Route Files All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.

What is a fallback route?

Now that you are familiar with the purpose of a Router, you will now learn about the Fallback Route which is a route a bundle passes through only when it cannot pass through any other route within a scenario hence the name fallback.


1 Answers

Got it.

Laravel 4 Syntax:

Route::any('{all}', array('uses' => 'myPageLoading@method'))->where('all', '.*');
like image 80
Pete Avatar answered Sep 28 '22 12:09

Pete