Error Undefined index: loading an excel - laravel 5

0

I would like to know if someone can help me with this error.

I'm trying to upload a file in excel to a table in a bd, but I get that error, and sincerely I've given it a thousand laps and I do not know why I do not take the data.

I'm trying to enter these values.

And this is my function.

 public function importexceladmisiones(Request $request)
    {

        if($request->hasFile('import_file')){
            $path = $request->file('import_file')->getRealPath();

            $data = Excel::load($path, function($reader) {})->get();

            if(!empty($data) && $data->count()){

                foreach ($data->toArray() as $key => $value) {
                    if(!empty($value)){
                        foreach ($value as $v) {        
                            $insert[] = 
                            [
                                'tipo_documentoentidad' => $v['tipo_documentoentidad'],
                                'numerodocumentoentidad' => $v['numerodocumentoentidad'],
                                'tipodocumentocliente' => $v['tipodocumentocliente'],
                                'numerodocumentocleinte' => $v['numerodocumentocleinte'],
                                'primerapellido' => $v['primerapellido'],
                                'segundoapellido' => $v['segundoapellido'],
                                'primernombre' => $v['primernombre'],
                                'segundonombre' => $v['segundonombre'],
                                'Fechacita' => $v['Fechacita'],
                                'Horacita' => $v['Horacita'],
                                'tiposervicio' => $v['tiposervicio'],
                                'examen' => $v['examen'],
                                'enfasis' => $v['enfasis'],
                                'profesional' => $v['profesional'],
                                'fechaadmision' => $v['fechaadmision'],
                                'estadoproceso' => $v['estadoproceso']
                            ];
                        }
                    }
                }


                if(!empty($insert)){
                    admisiones::insert($insert);
                    return back()->with('success','Insert Record successfully.');
                }

            }

        }

        return back()->with('error','Please Check your file, Something is wrong there.');
    }

This is the error that appears to me

So I charge it from my sight.

<div class="row">
  <div class="col-xs-12">
    <div class="box" style="border:1px solid #d2d6de;" >

             <div class="box-header" style="background-color:#f5f5f5;border-bottom:1px solid #d2d6de;">
            <h3>Importar archivo:</h3>
            <form style="border: 4px solid #a1a1a1;margin-top: 15px;padding: 20px;" action="{{ route('admin.ruta.import.excadmin') }}" class="form-horizontal" method="post" enctype="multipart/form-data">
              <input type="file" name="import_file" />
              {{ csrf_field() }}
              <br/>
              <button class="btn btn-primary">Subir Archivo</button>
            </form>
            <br/>
          </div>
    </div>
  </div>
</div>

Thanks for reading.

    
asked by Omar Noa 09.11.2018 в 22:33
source

1 answer

0

The error was because these fields Date and Horacita were thus in upper case in the base, and laravel passes it to minuscule, at the moment in which those values change in the base, the problem is fixed.

- 'Datecita' = > $ v ['Datecita'],

- 'Horacita' = > $ v ['Horacita'],

I hope it serves you something:)

    
answered by 23.11.2018 / 20:49
source