I have exported excel CSV file using maatwebsite
package in laravel
. But when I export it, it's show the raw data, how can I design this excel for show every data separately with it's title.
Here, is my exported data image link. http://prntscr.com/i08up8 Here is excel export code.
public function export()
{
$items = DB::table('userinformations')
->join('users', 'userinformations.user_id', '=', 'users.id')
->select('userinformations.fname','userinformations.lname','users.email')
->where('userinformations.payment_status',1)
->get();
$items=array($items);
Excel::create('items', function($excel) use($items) {
$excel->sheet('ExportFile', function($sheet) use($items) {
$sheet->fromArray($items);
});
})->export('csv');
}
The problem is the following line:
Laravel returns a collection. So this would mean you put the entire collection in an (one) array.
Try this instead:
This will cast your collection to an array and should solve your issue