taktik - laravel
This commit is contained in:
30
app/Services/PaginableResource.php
Normal file
30
app/Services/PaginableResource.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class PaginableResource
|
||||
{
|
||||
/**
|
||||
* @param array<int, T> $data
|
||||
* @param int $totalCount
|
||||
*/
|
||||
public function __construct(public array $data, public int $totalCount, public int $totalPages)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LengthAwarePaginator<int, T> $paginator
|
||||
* @return PaginableResource<T>
|
||||
*/
|
||||
public static function createFromLengthAwarePaginator(LengthAwarePaginator $paginator): PaginableResource
|
||||
{
|
||||
return new PaginableResource($paginator->items(), $paginator->total(), (int)ceil($paginator->total() / $paginator->perPage()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user