4 回答

TA貢獻1829條經驗 獲得超6個贊
你必須這樣使用
<form action="{{url('')}}/posts/{{$post->id}}" method="POST">
@csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
在你的路線中這樣使用
Route::post('/posts/{id}', ...)

TA貢獻1803條經驗 獲得超6個贊
我把我在 laravel 文檔中找到的隱藏方法放在了一起并且工作正常
<form action="/posts/{{$post->id}}" method="POST">
@csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}.
</textarea>
<input type="submit" class="btn btn-primary" value="edit">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

TA貢獻1799條經驗 獲得超9個贊
您可以執行以下操作:
<form action="{{ route('route.name', $post->id) }}" method="POST">
@csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
對于路線:
Route::post('/posts/{id}', 'Controller@function')->name('route.name');
- 4 回答
- 0 關注
- 186 瀏覽
添加回答
舉報