0

I am trying to retrieve results from an Excel file to save in the database column. Here is what I am trying:

public function addRecords(Request $request){
        $file = $request->get('file');
        //echo $file;
        Excel::load($file, function($reader){
            $results = $reader->get()->toArray();

            echo $results;
            foreach($results as $key => $value){
                $sim = new Sim();
                $sim->msisdn = $value['msisdn'];
                $sim->imei = $value['imei'];
                $sim->issued_to = $value['issued_to'];
                $sim->associated_with_employee = $value['associated_with_employee'];

                $sim->save();
            }
        });
    }

I am getting error:

Undefined index: msisdn|imei|issued_to|associated_with_employee.

What I am doing wrong here?

1 Answer 1

1

After an hour of trying different solutions and reading again http://www.maatwebsite.nl/laravel-excel/docs/import#formatting I found the error. The problem was I was not mentioning the sheet name. So, I fixed my error by adding

Excel::selectSheets('Sheet1')->load();

I hope it may help some future users.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.