samedi 23 septembre 2023

ErrorException (E_NOTICE) Undefined index: model Matt excel laravel

I am trying add data to database via excel file but it was working for a moment then it throws undefined index error

import function

 public function importExcel(Request $request)
    {

        if ($request->hasFile('file')) {

            Excel::load($request->file('file')->getRealPath(),  function ($reader) {
                foreach ($reader->toArray() as $row) {
                  
                    $data['date'] = $row['date'];
                    $data['chassis_no'] = $row['chassis_no'];
                    $data['model'] = $row['model'];
                    $data['color'] = $row['color'];
                    $data['supervisor'] = $row['supervisor'];
                    $data['technician'] = $row['technician'];
                    $data['job_card_type'] = $row['job_card_type'];
                    $data['total_amount'] = $row['total_amount'];
                    $data['remark'] = $row['remark'];



                    $jobcard = new Jobcard();

                    $jobcard->created_at =Carbon::parse($row['date']);
                    $jobcard->chasis_no = $row['chassis_no'];
                    $jobcard->model = $row['model'];
                    $jobcard->color = $row['color'];
                    $jobcard->supervisor = $row['supervisor'];
                    $jobcard->technician =  $row['technician'];
                    $jobcard->jobcard_type =$row['job_card_type'];
                    $jobcard->total_amount = $row['total_amount'];
                    $jobcard->created_id = auth()->user()->id;
                    $jobcard->remark = $row['remark'];


                    $jobcard->save();


                }
            });
            return back()->with('success', 'Your File Is Successfully Uploaded To Database!');
        }
        return back()->with('success', 'File Doesnt Uploaded!');
    }

View

 <div class="col-md-5">
    <div class="form-group">
        <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
            
            <div class="input-group">
                <div class="custom-file">
                  <input type="file" class="custom-file-input" name="file">
                  <label class="custom-file-label" for="inputGroupFile04">Choose file</label>
                </div>

              </div>
              <br><br>
              <div class="col-9">
                <button type="submit" class="btn btn-info waves-effect waves-light w-lg rbutton">
                    Upload
                </button>
            </div>

           </form>
    </div>
</div>

Excel File enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire