0

I try to import and show details in blade php

If comment this section, there's no error

$results = Excel::load('files/' . $file_name, function($reader){
        $reader->all();
    })->get();

i want to read and display the details from excel sheet to blade template here is my code:

public function ImportClients(){

    $file = Input::file('file');
    $file_name = $file->getClientOriginalName(); // save the file name
    $file->move('files/', $file_name); // file moved successfuly

    $results = Excel::load('files/' . $file_name, function($reader){
        $reader->all();
    })->get();

//  return view('clients', compact('results'));
}

This is the error msg: check the image for error msg

SAJJADH A.W
  • 31
  • 1
  • 1
  • 6
  • 1
    Sounds like the string contains `$` on either 0 or 1 (`$something`). `$pString{0}` or `$pString{1}` would be `$`, which doesn't exist as a key. You'll have to check the contents of the file. – aynber Jul 10 '19 at 16:30

1 Answers1

0

try this:

     if ($request->file('excel')!==null) {
 $inputFileName = $request->file('excel')->getRealPath();
 $spreadsheet = IOFactory::load($inputFileName);
 $data = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);

and then return view with data