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'),


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

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'),
Was this page helpful?