Level 13
Anyone could help me ? In resource collection how to change structure of json that grouped by a specific key ? for example this would work:
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'posts' => PostResource::collection($this->posts),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
with this :
Route::get('/user', function () {
return UserResource::collection(User::all());
});
But as soon i use groupBy in the collection it fails:
Route::get('/user', function () {
return UserResource::collection(User::get()->groupBy('name'));
});
// Error: Property [name] does not exist on this collection