Laravel's routing doesn't seem to be working as expected? From what I understand, if I intend to override a route, all I need to do is to put the expected route before the other one.
What I have is something like this:
Route::group(array('before'=>'defaultLoads'), function(){
Route::post('newsletter', 'NewsletterController@store');
Route::group(array('before'=>'login'), function(){
Route::resource('newsletter','NewsletterController');
}
});
Which I assumed that if i post to this route http://domain.com/newsletter
it should only run the defaultLoads route filter.
However, when I run php artisan routes
, I get this:
| | POST newsletter | newsletter.store | NewsletterController@store | defaultLoads, login | |
Although it reads the route correctly (php artisan loads that correct route in the correct place) but the resource route's filter affected the route even when it's not in that filter group.
So my question:
Is this how Laravel works?
If so, is it possible for me to override that POST->newsletter route without actually doing the following?
Route::group(array('before'=>'defaultLoads'), function(){ Route::post('newsletter', 'NewsletterController@store'); Route::group(array('before'=>'login'), function(){ Route::get('newsletter','NewsletterController@get'); Route::get('newsletter/{id}', 'NewsletterController@show'); //etc all the rest of the routes except post }});
Actually overriding in that way works in cases where you need to override the actual route that is being matched. For example when you need to override a route with a parameter, with something hardcoded:
In your case however, your route definitions are identical (both must match
newsletter
for apost
request). That means that the last one will override the first one (and any filters applied to it in the current context). So you should be overrding it after theresource
route definition:Your
artisan routes
for it should look like this now: