Summer Sale! All accounts are 50% off this week.

fadiabadir's avatar

Excel Grouping by Column

Is there a way to group by specific column in maatwebsite/excel other than using view as I want to store the excel and return the url in response

0 likes
2 replies
a4ashraf's avatar

@fadiabadir

you should convert your data into the collection and apply the collection method (Group_By)

see this sample code and documentation

$collection = collect([
    ['account_id' => 'account-x10', 'product' => 'Chair'],
    ['account_id' => 'account-x10', 'product' => 'Bookcase'],
    ['account_id' => 'account-x11', 'product' => 'Desk'],
]);

$grouped = $collection->groupBy('account_id');

$grouped->all();

https://laravel.com/docs/8.x/collections#method-groupby

fadiabadir's avatar

yes , but how to show these data each in a separate table on same excel sheet

Please or to participate in this conversation.