@if ($paginator->hasPages())
{{-- Previous Links --}}
@if (!$paginator->onFirstPage())
@endif
{{-- Pagination Elements --}}
@php
$current = $paginator->currentPage();
$last = $paginator->lastPage();
$delta = 2; // Number of pages to show around current page
$left = $current - $delta;
$right = $current + $delta;
$range = [];
$rangeWithDots = [];
$l = null;
@endphp
{{-- Build range of pages --}}
@for ($i = 1; $i <= $last; $i++)
@if ($i == 1 || $i == $last || ($i >= $left && $i <= $right))
@php array_push($range, $i) @endphp
@endif
@endfor
{{-- Add dots where gaps exist --}}
@foreach ($range as $i)
@if ($l)
@if ($i - $l === 2)
@php array_push($rangeWithDots, $l + 1) @endphp
@elseif ($i - $l !== 1)
@php array_push($rangeWithDots, '...') @endphp
@endif
@endif
@php array_push($rangeWithDots, $i); $l = $i @endphp
@endforeach
{{-- Render pages --}}
@foreach ($rangeWithDots as $i)
@if (is_int($i))
{{ $i }}
@else
{{ $i }}
@endif
@endforeach
{{-- Next Links --}}
@if ($paginator->hasMorePages())
@endif
@endif