jikan-rest/app/Http/Resources/V4/ClubCollection.php

79 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2020-07-11 11:53:22 +05:00
<?php
namespace App\Http\Resources\V4;
use Illuminate\Http\Resources\Json\ResourceCollection;
2021-01-16 10:50:42 +05:00
use Illuminate\Pagination\LengthAwarePaginator;
2020-07-11 11:53:22 +05:00
class ClubCollection extends ResourceCollection
{
/**
* The resource that this resource collects.
*
* @var string
*/
public $collects = 'App\Http\Resources\V4\ClubResource';
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
2020-07-17 00:13:07 +05:00
*
* @OA\Schema(
2022-02-11 18:31:14 +05:00
* schema="clubs_search",
2020-07-17 00:13:07 +05:00
* description="Clubs Search Resource",
*
2020-08-13 05:06:55 +02:00
* allOf={
* @OA\Schema(ref="#/components/schemas/pagination"),
* @OA\Schema(
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(
* ref="#/components/schemas/club"
* )
* ),
* )
* }
2020-07-17 00:13:07 +05:00
* )
2020-07-11 11:53:22 +05:00
*/
2021-01-16 10:50:42 +05:00
private $pagination;
public function __construct(LengthAwarePaginator $resource)
{
$this->pagination = [
'last_visible_page' => $resource->lastPage(),
'has_next_page' => $resource->hasMorePages()
];
$this->collection = $resource->getCollection();
parent::__construct($resource);
}
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
2020-07-11 11:53:22 +05:00
public function toArray($request)
{
return [
2021-01-16 10:50:42 +05:00
'pagination' => $this->pagination,
2021-01-13 12:01:43 +05:00
'data' => $this->collection
2020-07-11 11:53:22 +05:00
];
}
2021-01-16 10:50:42 +05:00
public function withResponse($request, $response)
{
$jsonResponse = json_decode($response->getContent(), true);
unset($jsonResponse['links'],$jsonResponse['meta']);
$response->setContent(json_encode($jsonResponse));
}
2020-07-11 11:53:22 +05:00
}