Count same relationship in multiple columns

I want to have some columns counting the same relationship, but with a few differences, such as different status. For example:
Tables\Columns\TextColumn::make('parking_spots_count')
->label('Total Parking Spots')
->counts('parkingSpots'),
Tables\Columns\TextColumn::make('parking_spots_available_count')
->label('Available Parking Spots')
->counts([
'parkingSpots' => fn (Builder $query) => $query->where('status', 'available'),
]),
Tables\Columns\TextColumn::make('parking_spots_count')
->label('Total Parking Spots')
->counts('parkingSpots'),
Tables\Columns\TextColumn::make('parking_spots_available_count')
->label('Available Parking Spots')
->counts([
'parkingSpots' => fn (Builder $query) => $query->where('status', 'available'),
]),
both of these columns work when used alone, but they don't work together (there's no error, they just don't show data). I tried using one of them as "sum" or changing the "make" name, but I could not make it work, I'm reading the docs but I can't find a best practice solution for that
1 Reply
Bruno Silva
Bruno SilvaOP9mo ago
⬆️
Want results from more Discord servers?
Add your server