26 lines
735 B
PHP
26 lines
735 B
PHP
<?php
|
|
|
|
namespace App\Api\Resources;
|
|
|
|
use App\Api\Resources\UserInfoBaseResource;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Jason\Api\Api;
|
|
|
|
class CommentResource extends JsonResource
|
|
{
|
|
public function toArray($request): array
|
|
{
|
|
$user = Api::user();
|
|
return [
|
|
'comment_id' => $this->id,
|
|
'user' => new UserInfoBaseResource($this->user),
|
|
'parent' => $this->when($this->parent_id, function () {
|
|
return new UserInfoBaseResource($this->parent->user);
|
|
}, function () {
|
|
return null;
|
|
}),
|
|
'is_me' => ! $this->user()->isNot($user),
|
|
'content' => $this->content,
|
|
];
|
|
}
|
|
} |