1
0
mirror of https://koodu.h-i.works/projects/thebadspace synced 2025-06-25 16:04:37 -05:00

Added Pagination Service class

Pagination is going to need some additional features in the near future,
so it made sense to give it it's own seperate class.
This commit is contained in:
ro
2024-02-20 12:57:33 -06:00
parent f96707f256
commit 682360c140
4 changed files with 59 additions and 31 deletions

View File

@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Auth;
class LocationRepository
{
protected $model;
private $limit = 15;
public function __construct(Location $model)
{
@ -54,28 +53,6 @@ class LocationRepository
->orderByDesc('updated_at')->limit(10)->get();
}
public function getPage($pageNum)
{
$range = $pageNum * $this->limit - $this->limit;
$active = $this->model::where("active", true)->where('actions_count', '>=', 2)->get();
$locations = $this->model::where("active", true)->where('actions_count', '>=', 2)
->limit($this->limit)->offset($range)->orderBy('id', 'asc')->get();
$pageCount = ceil(count($active) / $this->limit);
$next = $pageNum + 1;
if ($next > $pageCount) {
$next = 1;
}
$prev = $pageNum - 1;
if ($prev <= 0) {
$prev = $pageCount;
}
return $result = [$locations, $pageCount, $prev, $next];
}
public function addLocation(Request $request)
{
$fields = $request->validate([