Home > OS >  How to pass parameters to URL from Laravel Blade file
How to pass parameters to URL from Laravel Blade file

Time:02-11

I want to pass parameters from my blade file to the URL when the user presses the next or previous button. I want to achieve that when the user presses the button next, the parameters page will be equal to 1, and the value will keep increasing by one every time the user presses the following button. I know I have to do something in ref, but I do not know what code to put in. So the example URL after the user presses the next button will be www.example.com?page=1.

<div>
    <ul >
        <li >
            <a href=""><i ></i> Previous</a>
        </li>
        <li >
            <a href="">Next <i ></i></a>
        </li>
    </ul>
</div>

CodePudding user response:

If you only need to display simple "Next" and "Previous" links in your application's UI, you may use the simplePaginate method to perform a single, efficient query:

$users = DB::table('users')->simplePaginate(15);

By default, the views rendered to display the pagination links are compatible with the Tailwind CSS framework.

However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendor directory using the vendor:publish command:

php artisan vendor:publish --tag=laravel-pagination

CodePudding user response:

You can use Laravel default pagination such as

$users = User::paginate(15);

and use them in the blade such as

{{ $users->links() }}

There are many pagination option such as simplepaginate and other u can explore them as well hope this would be helpfull

CodePudding user response:

Like options you can learn about generating URLs to Named Routes. With this helper you can past URL in your blade

<a herf="{{ route('name_your_route', ['page' => 2]) }}">test</a>

If need more logic you can write in @php section, but its not good

If you need rewrite (redisign) standart pagination you can do this with customizing pagination view

  • Related