Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel resource routing - update throws "method not allowed" error

I have the following resource route:

Route::resource('pools', 'PoolsController');

I also have an edit form which should post to the controller's "update" method, set up like this:

{{ Form::open(array('route' => ['pools.update', $pool['id']])) }}

When I submit the form, it opens www.domain.com/pools/6 (6 being $pool['id'] above). However, instead of running the code in the update() method, it throws an error:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

Now, I've found Laravel's error reporting very unhelpful so far, and this is no exception. The error description is vague at best and does nothing to help me troubleshoot the issue.

I was under the impression that the update method should receive post data automatically when using resourceful routing. It has also worked in some examples before, using the same syntax.

So, can anyone tell me what might be going on here?

like image 397
sveti petar Avatar asked Oct 16 '15 11:10

sveti petar


1 Answers

to run the code in the update method, you must spoof a PUT request. look here: Form Method Spoofing

like image 56
Andrei C Avatar answered Oct 25 '22 04:10

Andrei C