Split Up Routes in Multiple Files

If you have a complex app with a lot of routes, you might want to split them into multiple files to keep track of them better.

This might seem difficult, as it's not documented on Laravel's website, but it's actually really simple.

How to split Laravel routes into multiple files

In order to achieve this we are going to use the Request:is() method, which allows us to filter routes. And the good part is that you can even use wildcards, so you can split them based on the part of app they represent.

Here you have an example on how to split your routes into multiple files. This code should go into the main routes.php file, where all routes are declared by default.

if(Request::is('frontend/*))
{
	require __DIR__.'/frontend_routes.php;
}

if(Request::is('admin/*))
{
	require __DIR__.'/admin_routes.php;
}

This way you can use as many files as you want for your routes.