Skip to content
Advertisement

Laravel RouteServiceProvider map function not called

I’m using the map function in the RouteServiceProvider to manipulate some routes before are being processed any further. When I run on my local machine everything runs fine but on the production server for some reason non of the map functions are being called. To make sure the bug was not for some reason in my own code I used the orignal RouteServiceProvider.php with just some echo’s added for testing purposes:

JavaScript

When running on production server I get:

JavaScript

When running on local machine:

JavaScript

So it seems on the production server the class is perfectly loaded and the boot function also is called but the none of the map function are. I’ve tried clearing every type of cache but the result remained the same. However during the cache clear it DOES call all the map functions:

JavaScript

Any idea what might be causing this or how to resolve it?

PS On the production server everything is deployed using PHP Deployer, but everything else is running fine so I assume that’s not the issue.

Advertisement

Answer

If you look at the frameworks default RouteServiceProvider, (Not the one that your application extends), You will see:

JavaScript

As you can see if ($this->routesAreCached()) { then the routes are loaded from cache, and $this->loadRoutes(); is what ultimately calls the map function of your RouteServiceProvider.

If you do php artisan route:clear it will stop the routes from being loaded from cache, and your map methods will be called on each request.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement