5
3

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] DELETE・PATCH・PUT を定義したときは、@method を使うと便利

Posted at

HTMLは PUT PATCH DELETE をサポートしていないので、これらを使いたいときは下記のように _method フィールドをhiddenで追加する必要がある。

<form action="/foo/bar" method="POST">
    <input type="hidden" name="_method" value="PUT">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

@method をつかうとさらに便利

もっと楽に _method input を作ってくれる @method というのもあるので、そちらを使うとよりらくちん。

<form action="/foo/bar" method="POST">
    @method('PUT')
    @csrf
</form>

参考

5
3
0

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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?