Josh R.
Josh R.

Reputation: 275

Does Laravel have a convention for organizing routes in routes.php?

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

Answers (3)

Ernest Okot
Ernest Okot

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

Adnan
Adnan

Reputation: 8180

Separate routes for large applications into multiple smaller route partial files that are automatically loaded at runtime.

Also you can

  1. Group routes
  2. Route namespaces
  3. Route prefixes

Useful examples

partial routes

split routes in different parts

organize routes

explained route using

break routes

Also i can recommend route caching for performance

Route caching tutorial

Upvotes: 4

Gummibeer
Gummibeer

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

Related Questions