[13.x] Fix mergeWhen() in JSON:API resource attributes
Merged
XU
18d ago+34+34+01234567890123456789-1-1-0123456789
Using mergeWhen() or merge() in a JSON:API resource's toAttributes() throws on every request:
class InvoiceResource extends JsonApiResource
{
public function toAttributes(Request $request): array
{
return [
'number' => $this->number,
'total' => $this->total,
$this->mergeWhen($request->user()->isAccountant(), [
'internal_notes' => $this->internal_notes,
]),
];
}
}
Error: Object of class Illuminate\Http\Resources\MergeValue could not be converted to string