Actually, I am trying to make pagination disable handler so that if I stay on the number 1 page the first page & the previous page will be disabled and the next page & last page will remain able to clickable, so as to, I can go next page and last page. In the same way, if I stay on the last page the next page & last page will be disabled and the previous page & first page will remain able to clickable. so as I can go to the previous page and the first page. How can I manage this system?
Pagination view design:
The first button is the first page , the second button is the previous page the third one is an input area for pagination number which the number of pages I want to go, the fourth button is the next page , the fifth button is the last page .
Function is here:
public function index(){ $master_product_list = EbayMasterProduct::with('variationProducts')->orderByDesc('id')->paginate(50); $master_decode_product_list = json_decode(json_encode($master_product_list)); return view('ebay.master_product.master_product_list',compact('master_product_list','master_decode_product_list')); }
Here is my pagination view code:
<div class="pagination-area"> <form action="{{url('pagination-all')}}" method="post"> @csrf <div class="datatable-pages d-flex align-items-center"> <span class="displaying-num"> {{$master_product_list->total()}} items</span> <span class="pagination-links d-flex"> <a class="first-page btn" href="{{$master_decode_product_list->first_page_url}}" data-toggle="tooltip" data-placement="top" title="First Page"> <span class="screen-reader-text d-none">First page</span> <span aria-hidden="true">«</span> </a> <a class="prev-page btn" href="{{$master_decode_product_list->prev_page_url}}" data-toggle="tooltip" data-placement="top" title="Previous Page"> <span class="screen-reader-text d-none">Previous page</span> <span aria-hidden="true">‹</span> </a> <span class="paging-input d-flex align-items-center"> <label for="current-page-selector" class="screen-reader-text d-none">Current Page</label> <input class="current-page" id="current-page-selector" type="text" name="paged" value="{{$master_decode_product_list->current_page}}" size="3" aria-describedby="table-paging"> <span class="datatable-paging-text d-flex">of<span class="total-pages">{{$master_decode_product_list->last_page}}</span></span> <input type="hidden" name="route_name" value="ebay-master-product-list"> </span> <a class="next-page btn" href="{{$master_decode_product_list->next_page_url}}" data-toggle="tooltip" data-placement="top" title="Next Page"> <span class="screen-reader-text d-none">Next page</span> <span aria-hidden="true">›</span> </a> <a class="last-page btn" href="{{$master_decode_product_list->last_page_url}}" data-toggle="tooltip" data-placement="top" title="Last Page"> <span class="screen-reader-text d-none">Last page</span> <span aria-hidden="true">»</span> </a> </span> </div> </form> </div>
You should take a look at the available paginator methods in the documentation.
https://laravel.com/docs/8.x/pagination#paginator-instance-methods
Specifically, you will need these:
$paginator->currentPage(); // get the current page number
$paginator->lastPage(); // get the page number of the last available page
If you want to remove the buttons, your code would look something like this:
<div class="pagination-area">
// ...
@if ($master_product_list->currentPage() > 1)
// first and previous buttons
@endif
// ...
@if ($master_product_list->currentPage() !== $master_product_list->lastPage())
// last and next buttons
@endif
// ...
</div>
If you only want to disable the buttons, you could add a disabled
class:
<a class="first-page btn {{ $master_product_list->currentPage() > 1 ? '' : 'disabled' }}">
// ...
</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.