Right, not sure if I doing something wrong or it's a problem with Illuminate\Database in Laravel.
My code:
$sth = Insect::leftJoin('types', 'types.id', '=', 'families.type_id')
->select('types.name as types','families.id','families.name')
->get()
->groupBy('types');
Result before groupBy is:
[
{
"types": "moths",
"id": 1,
"name": "Bombycidae"
},
{
"types": "moths",
"id": 2,
"name": "Brahmaeidae"
},
{
"types": "moths",
"id": 3,
"name": "Cossidae"
},
{
"types": "larvas",
"id": 6,
"name": "test"
}]
But with groupBy:
{
"moths": [
{
"types": "moths",
"id": 1,
"name": "Bombycidae"
},
{
"types": "moths",
"id": 2,
"name": "Brahmaeidae"
},
{
"types": "moths",
"id": 3,
"name": "Cossidae"
}
],
"larvas": [
{
"types": "larvas",
"id": 6,
"name": "test"
}
]
}
So my problem is, I want to get rid of that types in objects ...
Any ideas?