I'm writing a webservice API (in laravel 4.2).
For some reason, the routing to one of my controllers is selectively failing based on HTTP method.
My routes.php looks like:
Route::group(array('prefix' => 'v2'),
function()
{
Route::resource('foo', 'FooController',
[ 'except' => ['edit', 'create'] ]
);
Route::resource('foo.bar', 'FooBarController',
[ 'except' => ['show', 'edit', 'create'] ]
);
}
);
So, when I try any of GET / POST / PUT / PATCH / DELETE methods for theproject.dev/v2/foo
or project.dev/v2/foo/1234
urls, everything works perfectly.
But, for some reason, only GET and POST work for project.dev/v2/foo/1234/bar
. The other methods just throw a 405 (MethodNotAllowedHttpException).
(fyi, I am issuing requests via the Advanced Rest Client Chrome extension.)
What's going on?
What am I missing?
Route::resource: The Route::resource method is a RESTful Controller that generates all the basic routes required for an application and can be easily handled using the controller class.
x | Laravel 5. x). There are two ways you can modify the route names generated by a resource controller: Supply a names array as part of the third parameter $options array, with each key being the resource controller method (index, store, edit, etc.), and the value being the name you want to give the route.
Laravel Resources are another layer added on top of Laravel Eloquent models. It allows creating a uniform format or shapes for the data returned for these Eloquent models.
For the ones who are using Laravel versions > 4.2 use this :
php artisan route:list
This will give the list of routes set in your application. Check if routes for PUT and DELETE are allowed in your routes or not. 405 error is mostly because there is no route for these methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With