Tips for deactivating pagination indicators on the initial page, final page, as well as on the previous and subsequent pages within Laravel

My goal is to create a pagination disable handler that will effectively disable the first and previous page buttons when I am on the first page, allowing only the next page and last page buttons to be clickable. Similarly, when I am on the last page, the next page and last page buttons should be disabled while the first page and previous page buttons remain clickable. How can I implement this functionality?

Pagination view design:

The first button represents the first page, the second button is for the previous page, the third one is an input area where you can enter the desired page number, the fourth button is for the next page, and the fifth button represents the last page.

https://i.sstatic.net/nh7K0.png

Function implementation:

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'));
        }

Pagination view code snippet:

<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>

Answer №1

For those seeking guidance, it is recommended to refer to the paginator methods outlined in the documentation.
https://laravel.com/docs/8.x/pagination#paginator-instance-methods

Specifically, make use of the following methods:

$paginator->currentPage(); // retrieve the current page number
$paginator->lastPage();    // obtain the page number of the last available page

To eliminate the buttons, modify your code as demonstrated below:

<div class="pagination-area">

    // ...

    @if ($master_product_list->currentPage() > 1)        
        // display first and previous buttons
    @endif

    // ...

    @if ($master_product_list->currentPage() !== $master_product_list->lastPage())
        // show last and next buttons
    @endif

    // ...
  
</div>

If the intention is to simply disable the buttons, add a disabled class like so:

<a class="first-page btn {{ $master_product_list->currentPage() > 1 ? '' : 'disabled' }}">
    // ...
</a>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with the pitch of your rotating camera in Three.js?

I'm still getting the hang of three.js so please bear with me if this question seems a bit basic. My current challenge involves rotating a camera using the arrow keys. While the left and right (yaw) rotation works as expected, I'm encountering i ...

Using `this` within an object declaration

I am encountering an issue with the following code snippet: const myObj = { reply(text: string, options?: Bot.SendMessageOptions) { return bot.sendMessage(msg.chat.id, text, { reply_to_message_id: msg.message_id, ...options }) ...

Issue: The Material-UI DataGrid Column Filter is not compatible with Material-UI Dialog

I am currently facing an issue with my Material-UI DataGrid in React JS. I have successfully integrated the table inside a Material-UI DialogContent and everything seems to be working fine - ordering, renderCells, checkboxSelection, etc. However, I am enco ...

"Exploring the concept of master pages in web development with the combination

Recently, I have been developing a website that functions similarly to olx, displaying ads based on the visitor's location (for example, showing Mumbai ads if the visitor is from Mumbai). Initially, I was planning to create separate pages for each cit ...

Issue with radio button list not functioning properly in Mozilla and Chrome browsers

My web application has a radiobuttonlist with an onclick event. It functions properly in IE, but not in some other browsers. Here is a snippet of the code: <asp:RadioButtonList ID="rbgThreadStatus" runat="server" RepeatDirection=&quo ...

Encountering a runtime error in React while making an async call on a NextJS 13 page

I am currently working on implementing async calls using the new app layout in NextJS 13. I have been referring to the latest documentation page. However, I have encountered an error that I can't seem to resolve. https://i.sstatic.net/CpNmu.png Belo ...

Similar to Jquery ajax, Titanium also offers a powerful tool

Currently, I have been making an API call using Titanium in the following way: var url = "http://www.appcelerator.com"; var client = Ti.Network.createHTTPClient({ // callback when data is received onload : function(e) { Ti.API.info("Re ...

How can white space be maintained using <select> and <V-for> in Vue.js?

Using select and v-for to display values can be tricky when dealing with white space, such as "a a - ". Sadly, most of the white space gets removed when the values are shown and returned to the backend. Here is the code snippet illustrating the i ...

The Update Panel in IE9 is malfunctioning when attempting to click the button

Currently, I am working on a project using ASP.NET C#. I have implemented Select2 in an update panel. However, I am facing an issue where my button click does not work after a postback. To resolve this problem, I have added the following code to rebind ...

Adding a search feature to an app prior to its launch

We are currently working on a YouTube channel using Ionic and AngularJS. The search feature is only functional after loading videos through the API. We need to implement a condition where if the search box is empty, the videos should automatically load. ...

Even when autocomplete is disabled, Firefox continue to cache hidden input fields

I'm encountering an issue with a form that has the autocomplete attribute set to off. Within this form, there is a hidden input element (created using ASP.NET MVC's Html.HiddenFor() method): <input type="hidden" value="0" name="Status" id="S ...

Utilize TinyMCE in your WordPress plugin

How can I integrate TinyMCE into my WordPress plugin? I have a textarea in the backend script that I would like to convert into a TinyMCE WYSIWYG editable field. Is there a method to achieve this? The following code snippet is not yielding the desired re ...

"Ensuring Your SVG Icon is Perfectly Centered: A Step

My SVG icon is currently aligned to the left, but I want to center it. I tried using the following code, but it doesn't seem to be working: .parent{ display: flex; align-items: center; font-size: 13px; } span{ margin-right:10px } https://i.sstatic.ne ...

What is the best way to display the output of my Sudoku generator as an HTML table in Django?

Recently delving into Django, I've been working on creating a Sudoku web application. To generate the Sudoku puzzles, I developed a Python script named "Sudoku Generator.py" which produces matrices like this: [[3, 8, 2, 7, 5, 6, 1, 4, 9],[1, 4, 5, 2, ...

Accessing JSON data and populating a dropdown menu with JQuery

I am facing an issue with extracting values from a JSON array using jQuery. The structure of the array is as follows: [{ "": "Select your State/Region" }, { "BAL": "Balkh" }, { "BAM": "Bamian" }] Although I have attempted to loop through the array in ord ...

What could be causing the redirection to my php file in this particular contact form?

I have a contact form on my website that uses AJAX for submission. Everything seems to be working fine, but when the user clicks on the Submit button, they are redirected to the PHP file instead of staying on the page to see success or error messages. I wa ...

Identify specific zones on an image map

While working on my website, I utilized the services of a site called to generate an image map. However, I faced an issue where there was no visual indication that the continents were clickable links. My aim is to have an icon overlaid on each continent t ...

Resizing an image within an anchor tag

Currently, I am working on styling a page in NextJS. The challenge I'm facing is resizing an image that is inside an anchor within a div. Despite numerous attempts, the image refuses to resize as desired. I've experimented with applying properti ...

It's impossible to remove a dynamically added class from a button

I'm facing an issue with adding and removing classes from a button using jQuery. I added a new class to the button, then removed it, but now when I click the button again I want to revert back to the initial class. Unfortunately, my code is not workin ...

In search of grabbing an image from a list item and relocating it to sit before the division tagged with class "event-title"

I am struggling with selecting each list element within the ul and moving the image inside the div class="event-details" above the div with the class="event-title". This adjustment is necessary for achieving the desired styling since the wordpress Event pl ...