getEloquentQuery() many to may relation multi row per attachment
I am trying to customize the query using getEloquentQuery() and am having trouble getting the query to return what I am after. Any help would be greatly appreciated, also if there is a better way please let me know. It may be more a eloquent help request than anything.
Setup: - Activity 1, Staff A, Staff B - Activity 2, Staff B What I need the query to return for me table: - Activity 1 Staff A - Activity 1 Staff B -Activity 2 Staff B There is a bunch of other joins and stuff I need to do based on the staff member thus I am try to use getEloquentQuery(). For the life of me I cant wrap my head around how I need to format it to make it work.
Setup: - Activity 1, Staff A, Staff B - Activity 2, Staff B What I need the query to return for me table: - Activity 1 Staff A - Activity 1 Staff B -Activity 2 Staff B There is a bunch of other joins and stuff I need to do based on the staff member thus I am try to use getEloquentQuery(). For the life of me I cant wrap my head around how I need to format it to make it work.
1 Reply
I could maybe do it differently if I could access the results before the table gets them somehow? but the filters would be a nightmare.
I think I may actually have done it 😮
Further testing required.
public static function getEloquentQuery(): Builder
{
$parent = parent::getEloquentQuery()
->with('staff')
->join('activity_staff', 'activities.id', '=', 'activity_staff.activity_id')
->join('staff', 'activity_staff.staff_id', '=', 'staff.id')
->select('activities.*', 'staff.id as staff_table_id')
->groupBy('activities.id', 'staff_table_id')
return $parent;
}
Edit: don't include the ->orderBy('activities.id', 'asc'); or it will break your sortable() calls