The issue here is that the serializeDate method is not being called when using the JsonResource class. To solve this problem, you can override the toArray method in your Resource class and manually format the date using the serializeDate method.
Here's an updated version of your Resource class:
class Resource extends JsonResource
{
public function toArray($request): array
{
return [
'received_at' => $this->serializeDate($this->received_at),
];
}
}
By calling $this->serializeDate($this->received_at), you are manually formatting the date using the serializeDate method defined in your Model class.
This should give you the expected result:
received_at: "2023-07-22 09:46"