F
Filamentβ€’10mo ago
Oxygarum

Problem with creating query to show differences in values from variables and sort them

Hey Hey, I have a database that is getting input through a DeliveryLog resource form and so forth. In that employees need to input their deliveries handled within a shift. For simplicity I just called them deliveriesatstartofshift and deliveriesatendofshift. That is all working perfectly. Now I created a new Resource, Model and so forth in which I want to use a query to display the employees that made the most deliveries within the last seven days. For this I would want to take the difference between deliveriesatstartofshift and deliveriesatendofshift for all shifts the employees did in that time period. Employees can make multiple shifts of course within the last days so those differences would need to get added up. I worked for a while on it already, but am always running into the error "Cannot use "::class" on value of type null". This is what I made so far for the query:
public static function table(Table $table): Table
{


return $table


->query(function (Builder $query) {
return $query
->from('delivery_logs', 'dl')
->select(
'dl.badge',
DB::raw('SUM(dl.deliveriesatendofshift - dl.deliveriesatstartofshift) AS total_deliveries')
)
->whereBetween('dl.created_at', [Carbon::now()->subDays(7), Carbon::now()])
->groupBy('dl.badge', 'dl.id')
->orderByDesc('total_deliveries');
})
->defaultSort('total_deliveries', 'desc')
public static function table(Table $table): Table
{


return $table


->query(function (Builder $query) {
return $query
->from('delivery_logs', 'dl')
->select(
'dl.badge',
DB::raw('SUM(dl.deliveriesatendofshift - dl.deliveriesatstartofshift) AS total_deliveries')
)
->whereBetween('dl.created_at', [Carbon::now()->subDays(7), Carbon::now()])
->groupBy('dl.badge', 'dl.id')
->orderByDesc('total_deliveries');
})
->defaultSort('total_deliveries', 'desc')
Hopefully I explained it well enough πŸ˜„
2 Replies
Oxygarum
OxygarumOPβ€’10mo ago
Any ideas? πŸ˜„ Another bump. I am really stuck with that πŸ˜„
awcodes
awcodesβ€’10mo ago
Try this:
->query(Model::query())->modifyQueryUsing(function() {})
->query(Model::query())->modifyQueryUsing(function() {})
Want results from more Discord servers?
Add your server