3
4

More than 3 years have passed since last update.

【Laravel】PUT、DELETEリクエスト(疑似フォームメソッドについて)

Posted at

Laravelのhttpメソッドではgetリクエストとpostリクエストしか対応していない。
公式ドキュメント(https://readouble.com/laravel/5.6/ja/routing.html)

PUTやDELETEを使う際には、formで一旦POSTメソッドを指定して、hiddenで_methodプロパティ(隠しメソッド)を投げる。(疑似フォームメソッド)

laravelのBladeではディレクティブが使える


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

要するにこういうこと


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

ルートの定義はputでOK

Route::put($uri, $callback);
3
4
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
3
4