当我尝试删除录音时,我被卡在“删除”按钮上。
在我的 StudentController 中,我知道了
public function destroy($id)
{
$student = Student::find($id);
$student->delete();
return redirect()->route('student.index')
->with('success', 'Deleted successfully');
}
在我的 index.blade.php 中,我知道了:
@section('content')
<div class="px-content">
<div class="page-header">
<div class="row">
<div class="col-md-4 text-xs-center text-md-left text-nowrap">
<h1><i class="px-nav-icon ion-android-apps"></i>List </h1>
</div>
<hr class="page-wide-block visible-xs visible-sm">
<!-- Spacer -->
<div class="m-b-2 visible-xs visible-sm clearfix"></div>
</div>
</div>
<div class="row">
<div class="panel">
<div class="panel-body">
<div class="table-responsive">
<table class="table">
<a class="btn btn-sm btn-success" href="{{ route('student.create') }}">Create</a>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
@foreach($students as $student)
<tr>
<td> {{$student->firstname}}</td>
<td> {{$student->lastname}} </td>
<td>
<a class="btn btn-sm btn-warning" href="{{route('student.edit',$student->id)}}">Edit</a>
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
{!! $students->links() !!}
</div>
@endsection
对于文件夹 route
Auth::routes();
route::resource('student','AdminController');
Route::PATCH('/update/{id}','AdminController@update');
我不知道问题出在哪里?我想知道自己的错误,因为实际上我没有错误信息。
谢谢。
答案 0 :(得分:4)
您丢失了表单,因此请用这样的表单标签来包围按钮:
<form method="POST" action="{{ route('student.destroy', $student) }} ">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>