myrhorodskyi's avatar

Eloquent performance extremely slow when cast to JsonResource

I see to many calls of Illuminate\Database\Eloquent\Model::getCasts

Looks like this functions calls each time when access to any attributes and never cached.

DeviceListResource looks like this, but this is common issue, you can also use any Eloquent collection and just call ->where() to see the problem

class DeviceListResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'serialNumber' => $this->serial_number,
            ...
        ];
    }
}
0 likes
0 replies

Please or to participate in this conversation.