You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
name string
completed_orders int
assisted_orders int
completed_orders_pay_rate float
assisted_orders_pay_rate float
This is my export,
<?php
namespace App\Exports;
use App\Models\User;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
class UsersExport implements FromQuery, WithHeadings, WithMapping
{
use Exportable;
/**
* @return \Illuminate\Support\Collection
*/
public function query()
{
return User::query();
}
public function headings(): array
{
return ['Name', 'Completed Orders', 'Assisted Orders', 'Payout'];
}
public function map($user): array
{
return [
$user->name,
$user->completed_orders,
$user->assisted_orders,
'$' .
number_format(
$user->completed_orders * $user->completed_orders_pay_rate +
$user->assisted_orders * $user->assisted_orders_pay_rate
),
];
}
}
I want to sort the results by the field "Payout". How can I do it? Ofc I can calculate payout using SQL aggregate functions at fetch time but I don't want to do that. I have a bigger reason not to do that for my project case. I want to apply sorting after I get the data from the database.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a users table,
This is my export,
I want to sort the results by the field "Payout". How can I do it? Ofc I can calculate payout using SQL aggregate functions at fetch time but I don't want to do that. I have a bigger reason not to do that for my project case. I want to apply sorting after I get the data from the database.
Beta Was this translation helpful? Give feedback.
All reactions