Reputation: 275
I was contributing to a project that now has a routes.php file with like over 800 lines of routes. I was wondering if Laravel had a specific convention or a way to organize this so it doesn't have to have all routes in one large confusing file?
Upvotes: 2
Views: 1245
Reputation: 986
Also it would help to put some routes in different files. For example, you could create a folder called routes in your app folder, then add files in that folder. I usually have one file for authentication routes, then other files for the high level navigation items of the site.
don't forget to require those files in app/start/global.php
/*
|-------------------------------------------------------------------------
| in app/start/global.php
|-------------------------------------------------------------------------
|
*/
require app_path( 'routes/auth.php'); // Auth routes
require app_path( 'routes/articles.php'); // Article routes
maybe you should also consider using controller along side this technique to further slim you routes
Upvotes: 0
Reputation: 8180
Separate routes for large applications into multiple smaller route partial files that are automatically loaded at runtime.
Also you can
Useful examples
split routes in different parts
Also i can recommend route caching for performance
Upvotes: 4
Reputation: 197
The best ways are groups and don't list every single route but use controller routes. http://laravel.com/docs/4.2/routing#route-groups http://laravel.com/docs/4.2/controllers#implicit-controllers
If this doesn't help it's possible to split this file into multiple files, for example: routes/users.php, routes/posts.php and so on, and include these into the original routes.php
Upvotes: 1