Reputation: 15529
Consider the two following laravel routing directives (I am using laravel version 5.0.35, but I found the same behaviour in version 5.5):
Route::get('/a/b', function(){return "One";});
.
.
.
Route::get('/a/b', function(){return "Two";});
I know they don't make much sense, but consider them. Theoretically, the priority is that the first one would prevail over the second. But if you access the site with
http://whatever.com/a/b
the response is
Two
I guess this happens because even if the real selected directive is the first, it happened that the second one OVERWROTE the first one with his return value.
My question is: Is this the intended behaviour? Because it may be obvious when you only have two lines in your routes file, but not when you have dozens of them, and you inadvertently could duplicate the same directive and think that the return value of the first one is the one to be returned.
Upvotes: 1
Views: 90
Reputation: 38584
Is this the intended behavior?
Yes. Whenever you create a route with the same name, when the project load, it replaces the last one on the route file(LIFO method). When we add some changes on project, we used to run composer dump-autoload; php artisan route:clear
. with all these commands it dumps all the previous routes and loads new routes to application memory.
When I was doing a project I had the same issue. While inspecting I got the repeating route name issue. once fixed all runs smoothly.
check this as well - Multiple routes with same URL, but different names
Upvotes: 3