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


i following this documentation

to implement export excel in laravel 4 project.

so trying generate excel file array this:

//$results taken db query  $data = array(); foreach ($results $result) {    $result->filed1 = 'some modification';    $result->filed2 = 'some modification2';    $data[] = $result; } excel::create('filename', function($excel) use($data) {  $excel->sheet('sheetname', function($sheet) use($data) {      $sheet->fromarray($data);        });  })->export('xls'); 

but raises exception:

  object of class stdclass not converted string 

what doing wrong ?

update:

tried this:

$data = get_object_vars($data); 

which results in:

get_object_vars() expects parameter 1 object, array given 

this:

$data = (array)$data; 

results in initial error.

$data indeed array, it's made of objects.

convert content array before creating it:

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

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -