id, name: $json->name, createdAt: Carbon::parse($json->created_at), ); } public function toJson($options = 0): string { return json_encode($this->toArray(), $options); } /** @return array */ public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'created_at' => $this->createdAt->format('Y-m-d H:i:s'), ]; } }