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
Post a Comment