![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/Corals/modules/Utility/Transformers/API/Comment/ |
<?php namespace Corals\Modules\Utility\Transformers\API\Comment; use Corals\Foundation\Transformers\APIBaseTransformer; use Corals\Modules\Utility\Models\Comment\Comment; use Corals\User\Transformers\API\UserPresenter; use Illuminate\Support\Arr; class CommentTransformer extends APIBaseTransformer { /** * @param Comment $comment * @return array * @throws \Throwable */ public function transform(Comment $comment) { // $commentable_title = optional($comment->commentable)->getIdentifier(); $comment_author = optional($comment->comment_author); if ($comment_author) { $comment_author = $comment_author->setPresenter(new UserPresenter())->presenter(); } $transformedArray = [ 'id' => $comment->id, 'body' => $comment->body, // 'commentable_id' => $comment->commentable_id, // 'commentable' => $commentable_title, 'author_id' => $comment->comment_author_id, 'author' => $comment_author ? Arr::only($comment_author, ['id', 'full_name', 'email', 'phone_number', 'phone_country_code'] ) : null, 'comments' => (new CommentPresenter())->present($comment->comments)['data'], 'created_at' => format_date_time($comment->created_at), ]; return parent::transformResponse($transformedArray); } }