vendredi 22 novembre 2019

How To update multiple column using Import Excel Laravel 5.4

I want import my excel document to update any row with seems id in my excel document, so I'm using Laravel Excel, but my error is Call to a member function update() on array when I import my excel document

This is my function in controller :

if($request->hasFile('datasid')){
      $path = $request->file('datasid')->getRealPath();
      $data = Excel::load($path)->get();
      if($data->count()){
          foreach ($data as $key => $value) {
          $location = DB::table('locations')->select('id')->where('name', $value['location'])->pluck('id');
          $model = DB::table('statuses')->select('id')->where('name', $value['model'])->pluck('id');
          $status = DB::table('statuses')->select('id')->where('name', $value['sts'])->pluck('id');

          $where[] = $value['id'];
          $arr[] = [
            'parent_id'   => $value['sbu_id'],
            'code'        => $value['code'],
            'name'        => $value['pop'],
            'updated_at'  => Carbon::now(),
            'updated_by'  => Sentinel::getUser()->id];
            $array[] = SBU::where('id',$value['id']);
            $array->update($arr);  
          }


          if ($array) {
            return "ok";
          } else {
            return "kentot";
          }
      }
  }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire