I’m trying to implement onEachSide(1)
into custom pagination in bootstrap 5, but can’t understand how should I implement this.
Below is my code reference.
DistributorController.php
public function distributorList(Request $request)
{
$input = $request->all();
$search = isset($input['search']) ? $input['search'] : '';
$list = $this->distributorRepository->allList($input);
return view('admin.distributor.distributor')->with(['data'=>$list,'filter' => $search]);
}
allList
method inside distributorRepository.php
public function allList($input)
{
$res = $this->makeModel();
if (isset($input['search'])) {
$search = $input['search'];
$res = $res->where(function($query) use($search) {
$query->where('distributorId', 'LIKE', "%{$search}%" )
->orWhere ( 'name', 'LIKE', "%{$search}%" )
->orWhere ( 'mobile_no', 'LIKE', "%{$search}%" )
->orWhere ( 'email', 'LIKE', "%{$search}%" );
});
}
$res = $res->paginate(1)->withQueryString();
return $res;
}
custom-pagination.blade.php
@if ($paginator->hasPages())
<div class="position-absolute start-0">
<select class="select2 px-2 py-2" name="limit" id="limit">
<option value="15">15</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="all">All</option>
</select>
</div>
<div class="position-absolute end-0 d-flex">
<div class="px-2 py-2">
Showing {{ $paginator->firstItem() }}
to {{ $paginator->lastItem() }}
of {{ $paginator->total() }} results
</div>
<nav>
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev"
aria-label="@lang('pagination.previous')">Previous</a>
</li>
@endif
{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<li class="page-item disabled" aria-disabled="true">
<span>{{ $element }}</span>
</li>
@endif
{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<li class="page-item active" aria-current="page">
<a class="page-link" href="{{ $url }}">{{ $page }}
<span class="sr-only">(current)</span>
</a>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $url }}">{{ $page }}</a>
</li>
@endif
@endforeach
@endif
@endforeach
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next"
aria-label="@lang('pagination.next')">Next</a>
</li>
@else
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
<a class="page-link" href="#">Next</a>
</li>
@endif
</ul>
</nav>
</div>
@endif
But i want like this :-
Previous 1 2 … 9 10 11 … 19 20 Next
2
Answers
im new for laravel but i think you can use this
onEachSide
just sets the value to be used when creating pages, so you can modify the value before you pass the results to the view.