diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index 09f4d0c..ab3c41e 100644 --- a/src/Schema/ArticleSchema.php +++ b/src/Schema/ArticleSchema.php @@ -84,10 +84,10 @@ public function generateInner(): string '@type' => 'WebPage', '@id' => $this->url, ], - 'datePublished' => $this->datePublished->toIso8601String(), - 'dateModified' => $this->dateModified->toIso8601String(), - 'headline' => $this->headline, ]) + ->when($this->datePublished, fn (Collection $collection): Collection => $collection->put('datePublished', $this->datePublished->toIso8601String())) + ->when($this->dateModified, fn (Collection $collection): Collection => $collection->put('dateModified', $this->dateModified->toIso8601String())) + ->put('headline', $this->headline) ->when($this->authors, fn (Collection $collection): Collection => $collection->put('author', $this->authors)) ->when($this->description, fn (Collection $collection): Collection => $collection->put('description', $this->description)) ->when($this->image, fn (Collection $collection): Collection => $collection->put('image', $this->image)) @@ -95,4 +95,4 @@ public function generateInner(): string ->pipeThrough($this->markupTransformers) ->toJson(); } -} \ No newline at end of file +}