How to pass query string with pagination in laravel
How to pass query string with pagination in laravel
Hello everyone, in this post we will look at how to solve "How to pass query string with pagination in laravel" in programming.
You can pass query string using appends() method with pagination in laravel. You can use paginate on model object and after that can use appends(['key'=>'value']) method to pass the query string to url with pagination-
Pass multiple parameters as query string with pagination in laravel controller
//routes\web.php use App\Http\Controllers\HomeController; Route::get('/pagination-with-query-string', [HomeController::class, 'getRecords']); //app\Http\Controllers\HomeController.php use App\Models\User; public function getRecords(){ $users = User::select('*')->paginate(10); $users = $users->appends(['field1'=>'value1', 'field2' => 'value2']); return view('search')->with(['users'=>$users]); } //resources\views\search.blade.php <table> @foreach ($users as $user) <tr> <td> {{ $user->name }} </td> </tr> @endforeach </table> {{ $users->links() }}
You can add multiple parameters as query string to URL with pagination in laravel
Copy/Paste code and it will apped query string to url with pagination on click pagination link in laravel
Output :
http://localhost:8000/pagination-with-query-string?field1=value1&field2=value2&page=2
Related Queries
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to add unique records in pivot columns of Laravel pivot table
- Seed database using SQL file in Laravel
- How to get path from current URL in Laravel
- Array to string conversion laravel Controller
- How to create belongstomany relation using custom name on custom pivot table
- Conditional validation in laravel
- Laravel create table migration with model
- Print query in laravel
- Call to a member function pluck() on array
- Get today records in Laravel
- Input file with max size validation in laravel
- Display data in table using foreach in Laravel
- Check if Relationship Method Exists in Laravel
- How to return error message from controller to view in laravel
- Laravel upload file with original file name
- Route not defined in Laravel
- Update if exist else insert new record in laravel
- How to get file extension from input type file in laravel
- How to upload multiple images after preview in laravel using cropper js
- Best Practices for Error Handling in Production Server Code (example code)
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to get tomorrow and yesterday date in laravel
- Create project factory and seed data in laravel