小编Kay*_*aye的帖子

Laravel Modal 不断删除数据库中的最后一个 id

您好,我正在尝试在我的用户表中使用 Laravel 中的模式进行删除确认。我注意到删除按钮正在工作,但删除按钮总是删除表中的最后一个条目,并且在确认中我放置了一些,<p>Are you sure you want to delete {{$row->name}}</p> 但那里的名称始终来自最后一个条目。这是我的整个模态代码

<!-- Delete Modal -->
  <div class="modal fade" id="userDelete"  tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Delete User</h5>
        </div>
        <div class="modal-body">
          <p>Are you sure you want to delete {{$row->name}}</p> 
        </div>
        <div class="modal-footer">
         {!!Form::open(['action' => ['UserController@destroy', $row->id], 'method' => 'POST','class'=>'pull-right'])!!}
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          {{Form::submit('Delete',['class'=>'btn btn-danger'])}}
          {{Form::hidden('_method','DELETE')}}
          {!!Form::close()!!}
        </div>
      </div>
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

这是我的销毁控制器代码

public function destroy($id)
    {
        $users = User::find($id);
        if(auth()->user()->userType =="admin")
        {   
           
            $users->delete();
        } …
Run Code Online (Sandbox Code Playgroud)

php laravel-5

1
推荐指数
1
解决办法
716
查看次数

标签 统计

laravel-5 ×1

php ×1