LoginSignup
1
1

More than 3 years have passed since last update.

[laravel]formでpost以外を指定する方法

Posted at

formでpost以外を指定したいときはこんな感じになる

create.php
<form action="{{route('post.update',['post'=>$post->id])}}" method="post">
  //↓これ
    @method=('put'); 
    @csrf
    <label for="title">タイトル</label>
    <input type="text" id="title" name="title" value="$post->title">
    <input type="submit">
</form>

余談

僕はもともこんな感じでinputに入れてたけど上のようなスマートな書き方がしれてよかった。
これからは上記の書き方をしたいと思います。

create.php
<form action="{{route('post.update',['post'=>$post->id])}}" method="post">
    <input type="hidden" name="_method" value="delete">
</form>
1
1
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
1
1