F
Filament8mo ago
raptor

Table: Multiple counting on same relationship

How can I have multiple counts on the same relation in one table?
TextColumn::make('applications_count')->counts('applications')->label('Applications'),

TextColumn::make('applications_count')->counts([
'applications' => fn (Builder $query) => $query->where('completed', 1),
])->label('Completed applications'),
TextColumn::make('applications_count')->counts('applications')->label('Applications'),

TextColumn::make('applications_count')->counts([
'applications' => fn (Builder $query) => $query->where('completed', 1),
])->label('Completed applications'),
This just shows the last column "Completed applications", but the name has to be applications_count for the relation to work.
Solution:
Perhaps you could try something like: withCount ```php return $table ->modifyQueryUsing(function ($query) {...
Jump to solution
3 Replies
Solution
dissto
dissto8mo ago
Perhaps you could try something like: withCount
return $table
->modifyQueryUsing(function ($query) {
$query->withCount([
'applications',
'applications as completed_applications_count' => function ($query) {
$query->where('completed', 1),
},
]);
})
return $table
->modifyQueryUsing(function ($query) {
$query->withCount([
'applications',
'applications as completed_applications_count' => function ($query) {
$query->where('completed', 1),
},
]);
})
TextColumn::make('applications_count'),
TextColumn::make('completed_applications_count'),
TextColumn::make('applications_count'),
TextColumn::make('completed_applications_count'),
LeandroFerreira
LeandroFerreira8mo ago
I think you can use this
->modifyQueryUsing(fn(Builder $query) => $query->withCount(
[
'applications',
'applications as completed' => fn(Builder $query) => $query->whereCompleted(1),
]
)
)
->modifyQueryUsing(fn(Builder $query) => $query->withCount(
[
'applications',
'applications as completed' => fn(Builder $query) => $query->whereCompleted(1),
]
)
)
and use applications_count and completed yes, the same
raptor
raptorOP8mo ago
thanks, it worked
Want results from more Discord servers?
Add your server