Search code examples
phplaravelcachingroutesautoloader

Laravel routing cache


When I develop a Laravel application I used to clear cache after making any changes to routes\web.php or routes\api.php. Recently I was working on a project for a fellow and found out that the project does not need clearing cache every time I make a change in any of the files I have mentioned.

So I want to know what is the problem with the autoloader or what exactly is the general problem?


Solution

  • When you use commands like

    php artisan optimize

    php artisan route:cache

    your route files(under routes/) are being parsed and cached. Now, next requests will be routed from cached routes, not from routes/*.php.

    If you have used above commands, after making changes to route php files, you should re-cache them, or use

    php artisan route:clear

    to remove the cache. Then, next requests will be routed by routes/*php files.