Route Order and Overwrite defined in Package in Laravel

I faced a problem that I have a route which does not work in any case. It always show not found.

After researching around, I know that because of the ordered of the routes. To demonstrate, imagine I have 2 routes:

GET /post/{id} and GET /post/create

So in this case, the second route will be never called. Because Laravel matches the first route and immediately break at this point.

Back to my problem, I comment our all my routes except the problemable route. But it still does not work. I list all routes in the application by php artisan route:list command. And below is my result.

There is another route which defined by Laravel Spark package. It overwrites all my route because it called very first by the application. So I have to find out either call my routes before that route called or overwrite it.

I googled and found this answer https://stackoverflow.com/a/44724330/4184355. The answer said we can overwrite it by rearrange the Service Provider which define in config/app.php. I write RouteServiceProvider before SparkServiceProvider . I access my route again and get this error The bootstrap/cache directory must be present and writable. It means I have to clear the cache. So I run php artisan cache:clear and the problem is gone. My route works again.

Leave a comment

Your email address will not be published. Required fields are marked *