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