30 lines
1.0 KiB
PHP
30 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Api\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Jason\Api\Api;
|
|
|
|
class DynamicResource extends JsonResource
|
|
{
|
|
public function toArray($request): array
|
|
{
|
|
$user = Api::user();
|
|
return [
|
|
'dynamic_id' => $this->id,
|
|
'user' => new UserInfoBaseResource($this->user),
|
|
'description' => $this->description ?? '',
|
|
'pictures' => $this->pictures_url,
|
|
'is_me' => ! $this->user()->isNot($user),
|
|
'is_like' => $this->isLikedBy($user),
|
|
'liker_count' => $this->likers()->count(),
|
|
'liker' => UserInfoBaseResource::collection($this->likers()->limit(10)->get()),
|
|
'comments' => CommentResource::collection($this->comments()
|
|
->where('status', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->get()),
|
|
'created_at' => (string) $this->created_at,
|
|
'time' => $this->created_at->diffForHumans(),
|
|
];
|
|
}
|
|
} |