42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Cms\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
class PageCollection extends ResourceCollection
|
|
{
|
|
|
|
public function toArray($request): array
|
|
{
|
|
return [
|
|
'data' => $this->collection->map(function ($page) {
|
|
return [
|
|
'page_id' => $page->id,
|
|
'title' => $page->title,
|
|
'sub_title' => $page->sub_title,
|
|
'tags' => TagResource::collection($page->tags),
|
|
'description' => $page->description,
|
|
'slug' => $page->slug,
|
|
'cover' => $page->cover_url,
|
|
'pictures' => $page->pictures_url,
|
|
'clicks' => $page->clicks,
|
|
'created_at' => (string) $page->created_at,
|
|
];
|
|
}),
|
|
'page' => $this->page(),
|
|
];
|
|
}
|
|
|
|
protected function page(): array
|
|
{
|
|
return [
|
|
'current' => $this->currentPage(),
|
|
'total_page' => $this->lastPage(),
|
|
'per_page' => $this->perPage(),
|
|
'has_more' => $this->hasMorePages(),
|
|
'total' => $this->total(),
|
|
];
|
|
}
|
|
|
|
} |