第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

更新和刪除——我無法在 Laravel 框架中更新和刪除數(shù)據(jù)庫(kù)中的數(shù)據(jù)

更新和刪除——我無法在 Laravel 框架中更新和刪除數(shù)據(jù)庫(kù)中的數(shù)據(jù)

PHP
慕尼黑5688855 2021-12-24 09:32:16
我正在使用表單提交更新和從數(shù)據(jù)庫(kù)中刪除我的數(shù)據(jù)的請(qǐng)求,但我無法這樣做。我嘗試過使用不同的方法,但我無法解決這個(gè)問題。我在這個(gè)項(xiàng)目中使用 Laravel 5.4.36??刂破鳎簆ublic function update(Request $request, $id){    Student::where('id', $id)->update(['first_name' => 'vks', 'last_name' => 'pok']);}public function destroy(Request $id){    $student=Student::find($id);    $student->delete();}路線:Route::get('/student/about', 'BksController@about');Route::get('/student/service', 'BksController@Services');Route::get('create','BksController@create');Route::post('create','StudentController@create');Route::get('search','BksController@search');Route::post('search','StudentController@show');Route::get('/update','BksController@update');Route::put('update','StudentController@update');Route::get('/delete','BksController@delete');Route::delete('/delete','StudentController@destroy');Route::resource('student', 'StudentController');Route::get('/home', 'HomeController@index')->name('home');銷毀形式的刀片模板:@include('student.commonlayout')<div class='col-md-6 col-md-offset-3'>  <h1>DeleteData</h1>  <hr>  <form method="post" action="{{url('delete')}}">    {{csrf_field()}}    <div class="form-group">      <input type="text" name="first_name" class="form-control" placeholder="Enter your Id" />    </div>    <div class="form-group">      <input type="submit" class="btn btn-primary"/>    </div>  </form></div>更新表單的 Blade 模板:@include('student.commonlayout')<div class='col-md-6 col-md-offset-3'>  <h1>update Data</h1>  <hr>  <form method="post" action="{{url('update')}}">    {{csrf_field()}}    <div class="form-group">      <input type="text" name="id" class="form-control" placeholder="Enter your id" />    </div>更新時(shí),我收到以下錯(cuò)誤:RouteCollection.php 第 251 行中的 MethodNotAllowedHttpException刪除時(shí),我收到類似的錯(cuò)誤:RouteCollection.php 第 251 行中的 MethodNotAllowedHttpException
查看完整描述

2 回答

?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

我在您的任何刪除或更新路由中都沒有看到 POST 方法。


  Route::get('/update','BksController@update');

  Route::put('update','StudentController@update');

  Route::get('/delete','BksController@delete');

  Route::delete('/delete','StudentController@destroy');

當(dāng)您單擊表單中的按鈕時(shí),它會(huì)執(zhí)行 HTTP 發(fā)布。因此,將您的路線更改為相應(yīng)Route:post(...)地匹配。


查看完整回答
反對(duì) 回復(fù) 2021-12-24
?
一只萌萌小番薯

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊

使用Route::resource(...)將創(chuàng)建HTTP請(qǐng)求方法途徑DELETE的destroy行動(dòng),并PUT為update行動(dòng)。這意味著您在提交表單時(shí)必須使用這些方法。


不幸的是,HTML 表單不支持PUT或DELETE。這就是為什么 Laravel 使用一個(gè)名為的特殊隱藏輸入_method,它應(yīng)該包含正確的方法。表單本身應(yīng)該通過POST. 這就是您的更新表單的樣子(省略字段和其他標(biāo)記):


<form method="post" action="{{ url('update') }}">

  @method('put')

  {{ csrf_field() }}


  <!-- Your fields here -->

</form>

該指令@method('put')將生成以下 html <input type="hidden" name="_method" value="put">。


您可以在官方文檔中閱讀有關(guān)此主題的更多信息。


查看完整回答
反對(duì) 回復(fù) 2021-12-24
  • 2 回答
  • 0 關(guān)注
  • 180 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)