init
This commit is contained in:
26
app/Api/Resources/CommentResource.php
Normal file
26
app/Api/Resources/CommentResource.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user