phplaravelrouteslumen

Splitting Laravel / Lumen routes in multiple files


Lumen framework comes with the routes/web.php file. Reading about how to split the routes in multiple files I came across Laravel documentation (not Lumen) and there it seems pretty clear.

@see https://laravel.com/docs/6.x/routing#basic-routing >>> The Default Route Files

It states

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework. The routes/web.php file defines routes that are for your web interface. ...

Routes defined in the routes/api.php file are nested within a route group by the RouteServiceProvider. Within this group, the /api URI prefix is automatically applied so you do not need to manually apply it to every route in the file. You may modify the prefix and other route group options by modifying your RouteServiceProvider class

So you can just add other route files and edit the app/Providers/RouteServiceProvider.php class, this seems pretty straight and clear.

Just that Lumen doesn't have any app/Providers/RouteServiceProvider.php class

So then what's the best way to define your own route files without mangling the framework?


Solution

  • The equivalent in Lumen is located in /bootstrap/app.php.

    You can add routes file entries there appropriately. As you can see, there isn't really a specific API for adding files or anything. So just write the logic as you see fit.