Reputation: 23
my first idea is to send two parameters to DELETE operation!
<form action="{{ url('admin/sco/'.$sco->sno,$sco->cno) }}" method="POST" style="display: inline;">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger">删除</button>
</form>
then,it is the destroy function!
public function destroy($sno, $cno)
{
$query = DB::table('scos')->where('sno', $sno)->where('cno', $cno);
$query->delete();
return redirect()->back()->withInput()->withErrors('删除成功!');
}
but i get the result with NotFoundHttpException
i think where problem exists is i have not passed the parameters correctly. how can i do it? addtional information: 'sno' means student number, 'cno' means class number, i have to delete a specific record with the two numbers.
Upvotes: 0
Views: 54
Reputation: 3547
Try this solution:
In routes:
Route::post('/admin/sco/{sno}/{cno}', 'Your_controller@your_action')->name('sco.delete');
In views:
<form action="{{ route('sno.delete', ['sno' => $sco->sno, 'cno' => $sco->cno]) }}" method="POST" style="display: inline;">
Hope it help you :)
Upvotes: 1