5

Since in Laravel 5 the form builder class is absent (you can add it, I know), how can I make put, patch and delete requests to match those routes without using any form builder class, just plain Laravel?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Luuk Van Dongen
  • 2,391
  • 6
  • 26
  • 40

1 Answers1

7

You should try adding:

<input name="_method" type="hidden" value="DELETE">

to your form. This is what Form generator do in Laravel 4 - it simply adds hidden input with name _method.

Of course for DELETE value in above example you can put any other methods

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • Do you actually recommend using this over a regular POST method? Somewhere I read that this spoofing is done merely for semantic reasons and to keep the REST principles intact over the fact that changing the method actually has any function – Luuk Van Dongen Sep 30 '14 at 08:39
  • @LuukVanDongen As far as I know, this is technique to allow requests other than put and post. So probably POST will work if you simply add to your form `method="post"` however I haven't tested it because I use Form builder for creating forms – Marcin Nabiałek Sep 30 '14 at 08:44
  • Okay, but the same can be achieved by using just a post method and different endpoints. Like doing a POST on for example /products/312/delete could have te same function as a DELETE method on /products/312. So for functionallity it is not mandatory. – Luuk Van Dongen Sep 30 '14 at 08:54
  • This might help clarify the requests: http://stackoverflow.com/a/14757041/1317935 - but Marcin is 100% correct - this is the way to do it – Laurence Sep 30 '14 at 17:48