
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
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 get the id of last record from collection object in laravel view
- Laravel create default admin user
- Submit form without CSRF token in Laravel
- Insert values in pivot table dynamically in laravel
- Delete all related comments on deleting a post in Laravel
- How to display validation error in laravel
- 419 page expired error in Laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Generate random string lowercase in Laravel
- How to prevent host header attack in Laravel
- How to insert ckeditor data into database in Laravel?
- Extract only time from datetime in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Get current month records in laravel 7/8
- Get laravel version
- Ajax GET request in laravel
- How to get query string value in laravel
- How to use bootstrap pagination in laravel 8
- How to delete record in Laravel with ajax
- How to start websocket server in laravel
- How to add class to tr in table using foreach in laravel
- How to set column as primary key in Laravel model
- How to pass data to partial view file in laravel
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Laravel change date format