Skip to content

Instantly share code, notes, and snippets.

@glaphire
Created August 11, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaphire/63ef6738c1e70a228a60ab22b39698c1 to your computer and use it in GitHub Desktop.
Save glaphire/63ef6738c1e70a228a60ab22b39698c1 to your computer and use it in GitHub Desktop.
<?php
namespace App\Pagination;
use JsonSerializable;
class PaginatedCollection implements JsonSerializable
{
private $items;
private $total;
private $count;
private $links = [];
public function __construct($items, $totalItems)
{
$this->items = $items;
$this->total = $totalItems;
$this->count = count($items);
}
public function addLink($ref, $url)
{
$this->links[$ref] = $url;
}
public function jsonSerialize()
{
return [
'items' => $this->items,
'total' => $this->total,
'count' => $this->count,
'links' => $this->links,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment