Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions shared/Transformers/PostTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PostTransformer implements TransformerInterface
{
/**
* Transforms the post data
* @param $item
* @param mixed $item
* @return array
*/
public function transform($item): array
Expand All @@ -35,9 +35,24 @@ public function transform($item): array
'uuid' => $item->uuid,
'title' => $item->title,
'content' => markdown_to_html($item->content, true),
'image' => $item->image && $item->user_directory ? $item->user_directory . '/' . $item->image : null,
'image' => $this->buildImagePath($item),
'date' => date('Y/m/d H:i', strtotime($item->updated_at)),
'author' => $item->firstname . ' ' . $item->lastname,
];
}

/**
* Builds the image path for the given item.
*
* @param $item
* @return string|null
*/
private function buildImagePath($item): ?string
{
if ($item->image && $item->user_directory) {
return $item->user_directory . '/' . $item->image;
}

return null;
}
}
Loading