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 create event and listener in laravel ?
- Create records using relationship in laravel
- Retain selected value of select box in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- How to display HTML tags In Laravel blade
- Trying to get property 'title' of non-object
- How to get route name on visit URL in laravel
- Session Doesn't Work on Redirect
- Update email with unique validation in laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- How to get route method name in Laravel
- If condition in foreach loop in laravel
- JQuery each loop on json response after ajax in laravel
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Return view from route Laravel
- How to get database name in Laravel 9 ?
- How to customize pagination view in laravel
- How to create and run user seeder in laravel
- How to use or operator in laravel
- Return redirect laravel not working
- Retrieve count of nested relationship data in Laravel
- How to add active class to menu item in laravel
- Calculate age from date of birth in Laravel
- Conditional where clause in Laravel