Object of class stdClass could not be converted to string - laravel

后端 未结 6 1144
野性不改
野性不改 2021-02-18 17:04

I am following this documentation

to implement export to Excel in my laravel 4 project.

So am trying to generate excel file from array like this:



        
6条回答
  •  北海茫月
    2021-02-18 17:13

    $data is indeed an array, but it's made up of objects.

    Convert its content to array before creating it:

    $data = array();
    foreach ($results as $result) {
       $result->filed1 = 'some modification';
       $result->filed2 = 'some modification2';
       $data[] = (array)$result;  
       #or first convert it and then change its properties using 
       #an array syntax, it's up to you
    }
    Excel::create(....
    

提交回复
热议问题