I have a resource which looks like so;
class TestingResource extends JsonResource
{
public function toArray($request)
{
return [
'first' => AnotherResource::collection($this->first),
'second' => AnotherResource::collection($this->second),
];
}
}
What I want to do is combine the 2 so I only have to return one element like so;
class TestingResource extends JsonResource
{
public function toArray($request)
{
return [
'first' => AnotherResource::collection($this->combined),
];
}
}
I tried doing array_merge($this->first, $this->second)
but it doesnt work.
Is there any way of getting this to work?