DEV Community

Discussion on: How to Improve Routing In Laravel

Collapse
 
bdelespierre profile image
Benjamin Delespierre • Edited

Dealing with thousands of routes, we ended up doing the following:

  • never use the Route::resource helper, with lots of routes it does more harm than good
  • create one RouteServiceProvider per entity (e.g. ContractRouteServiceProvider)
  • isolate each group in a different method
  • methods look like this
    public function mapContract()
    {
        Route::middleware(['web', 'auth'])
            ->namespace($this->namespace)
            ->group(function () {
                Route::get('addworking/contract', [
                    'uses' => "ContractController@dispatcher",
                    'as'   => "addworking.contract.contract.dispatcher",
                ]);

With the same pattern everywhere, makes it super easy to find a route using its name or its URI :-)

Collapse
 
sanz profile image
Sanz

Thanks, I appreciate your feedback. This surely is a clean approach to structure routes.