Models and relationship
ModelA ModelB ModelA belongs to ModelB ModelB has many ModelA
$arrayModelA = ModelA::where('some_fk',$id)->get(); $groupedModelA = arrayModelA->groupBy('model_b_id')
[ model_b_id => ModelACollection some_other_model_b_id => ModelACollection ]
[ SomeModelBObject => ModelACollection SomeOtherModelBObject => ModelACollection ]
My grouped query is working fine grouping it by the model_b_id. The problem is that it doesn't bring the modelB object instead it groups simply by the field id. I need to have the entire object.
How can I achieve this?