F
Filament2y ago
Dex

Table record with GroupBy statement

I have the following query:
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id');
}
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id');
}
So MySQL doesn’t allow single grouping, through the strict mode, so I grouped by the whole select Params:
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id', 'user_activities.id', 'user_activities.created_at', 'data.modules.title', 'data.activities.title', 'data.activities.points');
}
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id', 'user_activities.id', 'user_activities.created_at', 'data.modules.title', 'data.activities.title', 'data.activities.points');
}
But when I select all datasets into the table, every record has his own page. How can I fix that?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server