简体   繁体   English

CRUD-在Laravel上删除

[英]CRUD - Delete on Laravel

I am stuck on my button "delete" when I try to delete a recording nothing happens. 尝试删除录音时,我被卡在“删除”按钮上,没有任何反应。

In my StudentController I have that: 在我的StudentController中,我有:

public function destroy($id)
    {
        $student = Student::find($id);
        $student->delete();
        return redirect()->route('student.index')
                    ->with('success', 'Deleted successfully');
    }

And in my index.blade.php I have that: 在我的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

For the folder route 对于文件夹路由

Auth::routes();
route::resource('student','AdminController');
Route::PATCH('/update/{id}','AdminController@update');

I don't understand where is the problem ? 我不明白问题出在哪里? I would like to know my error because I don't have of error message in fact. 我想知道自己的错误,因为实际上我没有错误信息。

Thank you in advance. 先感谢您。

You are missing the form so surround your button with a form tag like this: 您缺少表单,因此请用如下表单标签包围按钮:

<form method="POST" action="{{ route('student.destroy', $student) }} ">
   @csrf
   @method('DELETE')
   <button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM