0
I have an ajax that sends data from my selects to my controller and from there I do a check and query, so far everything is working perfectly. The problem is that the last select that sends is an array, because it is a select Multiple, and Dái am not being able to pass it correctly. Someone to give a hint? I know it’s easy, but I’m not getting it. Detail: I need this Function (d), because I think it is important in yajra Datatable.
View:
<div class="form-group">
     {{ Form::select('subunidade[]', $subunidades, null, array('class' => 'form-control js-example-basic-multiple', 'id' => 'subunidade', 'multiple' => 'multiple')) }}
</div>
Ajax:
<script type="text/javascript">
      var subunidades = new Array();
      $("select[name='subunidade[]']").each(function(){
         subunidades.push($(this).val());
      });
    var oTable = $('#example').DataTable({
           dom: "<'row'<'col-xs-12'<'col-xs-6'l><'col-xs-6'p>>r>"+
               "<'row'<'col-xs-12't>>"+
               "<'row'<'col-xs-12'<'col-xs-6'i><'col-xs-6'p>>>",
           processing: true,
           serverSide: true,
           ajax: {
               url: 'filterBusca',
               data: function (d) {
                   d.nome = $('input[name=nome]').val();
                   d.operador = $('select[name=operador]').val();
                   d.idade = $('input[name=idade]').val();
                   d.unidade = $('select[name=unidade]').val();
                   d.subunidade = $('select[name=subunidade').val();
               }
           },
           columns: [
               {data: 'id', name: 'id'},
               {data: 'matricula', name: 'matricula'},
               {data: 'nome', name: 'nome'},
               {data: 'cpf', name: 'cpf'},
               {data: 'idade', name: 'idade'},
               {data: 'unidade', name: 'unidade'},
               {data: 'sub_unidade', name: 'sub_unidade'},
           ]
       });
       $('#Filtrar').on('submit', function(e) {
           oTable.draw();
           e.preventDefault();
       });
  </script>
Controller:
if ($subunidade = $datatables->request->get('subunidade')) {
      $datatables->whereIn('sub_unidade.id', "$subunidade");
It’s not going as array to the controller or it’s not going at all?
– Sam