1
votes

i'm using laravel maatwebsite excel,

i tried passing variable and do some action and return as array to export,

So i get the Error when i tried to pass array to the main controller for excel export(download)

my main controller

public function excel_export(Request $request){

return Excel::download(new UsersExport($request->exp_vlas), 'users.xlsx');

}

here iam passing variable to the collection

my export controller

public function collection(){


        $instruments = implode(",",$this->id);

        $instruments = explode(",",$instruments);

        //$i=0;
        foreach ($instruments as $instrument) {
            $instr_list = DB::table('instruments')->select('*')->where('id',$instrument)->get()->toArray();
            $arr_instrulist[] = $instr_list;
            $instrument_var[] = $instrument;
            $instr_list = "";
            //$i++;
        }


        $arr_instrulist_excel[] = array('Instrument Name', 'Serial', 'Qa id', 'Unit', 'Range');

         foreach($arr_instrulist as $arr_instrulists){

            //$arr_instrulists = array($arr_instrulists);

              $arr_instrulist_excel[] = array(
               'Instrument Name'  => $arr_instrulists[0]->instrument_name,
               'Serial'   => $arr_instrulists[0]->serial,
               'Qa id'    => $arr_instrulists[0]->qa_identification_no,
               'Unit'  => $arr_instrulists[0]->unit,
               'Range'   => $arr_instrulists[0]->range
              );

        }


         return $arr_instrulist_excel;
}

when tried to return this($arr_instrulist_excel) i get an error

please give me some solution for this.

Error i'm facing

error i'm facing

1
please post the exact error messageADyson
updated my post check out.teenage vampire
No I meant the full error including line number, stack trace etc. If that's not shown on your page, it should be in a log file somewhere.ADyson

1 Answers

8
votes

You are telling export script to get your data from Collection but you are giving an array. You should return collection instead. You can simply wrap your array in collection like that:

return collect($arr_instrulist_excel);