duanji1026 2017-05-16 10:04
浏览 105
已采纳

Laravel删除多个复选框

I'm new to deleting multiple checkboxes so i need a little help. I've been searching the web for like hours but i can't fix my problem.

I have a todo list and there are some todo's showing from the database on my webpage.How can i delete all selected checkboxes in one click?

I'm using Laravel 5.4

ToDoController:

public function destroy()
   {
    $checked = Request::input('checked')['checked'];
    $checked->delete();
   }

Blade:

@foreach ($todo as $todoresult)

            <form method="get" action="/todo/destroy/">

          <div class="checkbox">
           <label><input type="checkbox" value="{{$todoresult->id}}" name="checked[]">{{$todoresult->todoinfo}}</label><br />

          </div> 

            @endforeach

            </div>
            <div class="panel-footer">

            <button class="btn btn-success" type="submit">Verwerken</button>

            </form>

Route:

Route::get('/todo/destroy/', 'ToDoController@destroy');

How would i do this? And how would my routing be like?

  • 写回答

2条回答 默认 最新

  • du4822 2017-05-16 10:07
    关注

    Something like the following would probably work:

    public function destroy() {
       $checked = Request::input('checked',[]);
       foreach ($checked as $id) {
            Todo::where("id",$id)->delete(); //Assuming you have a Todo model. 
       }
       //Or as @Alex suggested 
       Todo::whereIn($checked)->delete();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端