Quick Contact

    Example of Laravel-:

    Let’s take example of pagination in Laravel.

    Pagination in Laravel include the information about pagination, making controller and router, passing of data to view, writing of code for the pagination, add styling.

    So if you start with pagination then in pagination, when you have a long list of the users or companies that you want to show on the page but if this is thousands then you cannot show on the single page so that you have to split the number of rows to the different pages. So here for this you have to use the pagination. Such as-:

    When you click on the first then a limited amount of companies or user will be shown the second, third and fourth. So it will be nice to get the data from the database as well as user experience will also good so let’s start with code-:

    First make a controller and router, so open cmd and make controller as “php artisan make:controller companies” and press enter and your controller will be created. So now in controller the function with the name of list is created as-:

    So that by creating function you can get that data here as well as connection, so first of all write some dummy text in function in “echo”.

    Now define the router in another web.php file. Show the list “url” and then check if it’s working.

    Now make a view so that you can just pass the data there. So create new file in views like companies.blade.php and fetch the data in this. To fetch you need to use a database class in function you created in controller. So write “illuminate\support\facades\DB;”

    Complete function code is written as-:

    Now check on local host with table name or url, the database will open and list will be shown by open respective name i.e. company-:

    Just put the table name and use the pagination method and in pagination method, just pass the data that you want to catch up on the every page so first of all you want to put ‘10’ that means on every page 10 that you will be coming here and let’s just pass this data to the view. It should be the two parameters one for that company and second one is the data which is come inside the array. So the code will be-:

    So let’s go to blade view page and let’s check first of all data coming or not

    Let’s check with the taller data variables and now try to run it. But this is not pagination so change the code of view by using loop.

    Now check the address on localhost-:

    Choose some styling like pixel etc.
    You can go to front and back by clicking it. But if you have more data then put pages limit of number of item on pages is four at a time with 20 records. So only four items on a page will be going to show. So in long list next arrow will be shown after 4 or 5 i.e. the limit you used to put in it.
    So as page is shown here, this is all about pagination.

    Copyright 1999- Ducat Creative, All rights reserved.