explode () ожидает, что параметр 2 будет строкой, а массив задан multipUpdate - PullRequest
0 голосов
/ 12 февраля 2020

У меня есть набор данных SALARIES с флажками и выбор, заполненный CHANTIERS, я хочу обновить несколько CHANTIERS из SALARIES, выбранный в select, согласно проверенной строке, но это дает мне ошибку. Я думаю, что ошибка в функции updateMultiple.

SalarieController. php

 public function updateMultiple(Request $request){
        Salarie::find(explode(',',Request('id')))->each(function($item) {
         $item->update(['chantier' => Request('chantier')]);
        });
        return response()->json(['status'=>true]); 
    }

wep. php

Route::get('affectation','SalarieController@affectation'); 
Route::post('affectation', ['as'=>'salarie.multiple-update','uses'=>'SalarieController@updateMultiple']); 

effectation.blade. php

     <div class="form-group col-md-3">
          <select class="form-control" id="chantier">
                  <option></option>
                   @foreach($chantiers as $chantier)
                  <option value="{{ $chantier->id }}">{{ $chantier->chantier}}</option>
                   @endforeach
          </select>
      </div>
      <div class="form-group col-md-4">
       <button class="btn btn-theme update-all" data-url="">Update All</button>
      </div>
 <table id="example" class="table table-striped table-bordered" style="width:100%">
                 <thead>
                  <tr>
                    <th><input type="checkbox" id="check_all"></th>
                    <th>nom prenom</th>
                    <th>cin</th>
                    <th>matricule</th>
                    <th>chantier</th>
                  </tr>
                 </thead>
                <tbody>
                  @foreach($salaries as $salarie)
                  <tr id="{{$salarie->id}}">
                    <td><input type="checkbox" class="checkbox" name="customer_id[]" value="{{$salarie->id}}" /></td>
                    <td>{{ $salarie->nom }} {{ $salarie->prenom }}</td>
                    <td>{{ $salarie->cin }}</td>
                    <td>{{ $salarie->matricule }}</td>
                    <td>{{ $salarie->chantier->chantier }}</td>
                  </tr>
                  @endforeach
                </tbody>

jQuery

   <script type="text/javascript">
    $(document).ready(function () {
        $('#check_all').on('click', function(e) {
         if($(this).is(':checked',true))  
         {
            $(".checkbox").prop('checked', true);  
         } else {  
            $(".checkbox").prop('checked',false);  
         }  
        });
         $('.checkbox').on('click',function(){
            if($('.checkbox:checked').length == $('.checkbox').length){
                $('#check_all').prop('checked',true);
            }else{
                $('#check_all').prop('checked',false);
            }
         });
        $('.update-all').on('click', function(e) {

          if(confirm("Are you sure you want to update this?"))
  {
   var id = [];
   var chantier;

   $(':checkbox:checked').each(function(i){
    id[i] = $(this).val();
   });

   if(id.length === 0){
    alert("Please Select atleast one checkbox");
   }else{
    let chantier = $('#chantier').val();
    $.ajax({
     url:"{{ route('salarie.multiple-update') }}" ,
     headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
     method:'post',
     data:{
           id:id,
           chantier:chantier,
           "_token": "{{ csrf_token() }}"
    },
     success:function(){
      for(var i=0; i<id.length; i++)
      {
      $('tr#'+id[i]).find('td:last-child').html(chantier);
      }
     }

    });
   } 
  }
  else
  {
   return false;
  }

    });
    });
</script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...