51
48

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelにフォームからPUT/DELETEリクエストを送る

Last updated at Posted at 2015-08-05

LaravelのRESTfulなルーティングにたいして、フォームからPUTやDELETEメソッドでリクエストを発行する必要がある。このときformタグのmethodにPUTやDELETEを指定しても、HTML formがそもそもこれらのメソッドに対応していないため、リクエストを発行できない。

<form method="put" action="/sample/100">
    <input type="text" name="name" />
    <input type="submit" />
</form>

こういうときは、formではPOSTメソッドを指定して、hiddenで_methodプロパティを投げれば良いらしい。

<form method="post" action="/sample/100">
    <input name="_method" type="hidden" value="PUT">
    <input type="text" name="name" />
    <input type="submit" />
</form>
51
48
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
48

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?