我正在使用表单提交更新和从数据库中删除我的数据的请求,但我无法这样做。
我尝试过使用不同的方法,但我无法解决这个问题。我在这个项目中使用 Laravel 5.4.36。
控制器:
public 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>
更新时,我收到以下错误:
RouteCollection.php 第 251 行中的 MethodNotAllowedHttpException
删除时,我收到类似的错误:
RouteCollection.php 第 251 行中的 MethodNotAllowedHttpException
米琪卡哇伊
一只萌萌小番薯