【问题标题】:Change the status of more than one option in Laravel在 Laravel 中更改多个选项的状态
【发布时间】:2021-08-09 16:35:18
【问题描述】:

我想更改多个选项的状态 在图中,选择我要更改的列,然后点击modal,选择状态,然后点击Change,所有选中的状态都变为选中状态 在 Laravel 中怎么样?

【问题讨论】:

  • 这似乎是前端的事情。但是,话虽如此,请提供更多详细信息和代码。

标签: php laravel laravel-7


【解决方案1】:

在刀片中添加

<table> <input type="checkbox" id="check-all" class="flat" ></th>  </table>

在模态中

 <input type="hidden" name="hidden_id" id="hidden_id" />

在 Ajax 中

 $(document).on('click', '#update', function(){

var id = [];
$('.status:checked').each(function(){
  id.push($(this).attr('id'));

          });
  $('#form_result').html('');   

$.ajax({
 url:"/order/"+id+"/edit",
 dataType:"json",
 success:function(html){ 
 $('#status_id').val(html.data.status_id); 
  $('#hidden_id').val(html.data.id);
   
 }
})
});

在控制器中

->addIndexColumn()
      ->addColumn('show', function($data){
        $checkbox = '<input type="checkbox" name="status[]" id="'.$data->id.'" class="all print" />';
      
        return $checkbox;

您必须发送隐藏在复选框中的 ID。 在控制器中你可以使用它

$ids_edit = explode(',', $request->hidden_id);


        foreach($ids_edit as $id){
            if($id){
                $order =Order::find($id);
                $order->status_id = $request->status_id; 
                $order->update();
                }
           }

【讨论】:

  • 我通过数据表发送ID return '';我该如何继续?
  • 是的,您必须通过 ajax 发送 ID 以将其编辑为 hidden_​​ids,然后您的状态 [] 将从您的模式中更新,我可以看到“جديد”作为要更新的状态。
  • 如何将 ids ajax 发送为 hidden_​​ids 进行编辑?
  • 使用刀片文件 您在表单中添加了这一行 是这样吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-24
  • 1970-01-01
  • 2018-11-14
  • 2017-03-06
  • 2019-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多