亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

laravel 不支持 put 方法

laravel 不支持 put 方法

PHP
莫回無 2023-04-28 15:57:44
我嘗試使用編輯路徑更新帖子,但是當我發送表單并使用更新功能時出現錯誤我的代碼是<form action="/posts{{$posts->id}}" method="POST">@method('PUT')@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">
查看完整描述

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}', ...)


查看完整回答
反對 回復 2023-04-28
?
慕碼人8056858

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>


查看完整回答
反對 回復 2023-04-28
?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

您在操作中 缺少/action="/posts/{{ $posts->id }}"



查看完整回答
反對 回復 2023-04-28
?
揚帆大魚

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');


查看完整回答
反對 回復 2023-04-28
  • 4 回答
  • 0 關注
  • 186 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號