
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 call controller function from view in Laravel
- Display success message in laravel
- Page loader in laravel
- Validation errors for multiple forms on same page Laravel
- JQuery each loop on json response after ajax in laravel
- Create project factory and seed data in laravel
- How to pass two variables in HREF in laravel
- How to get all posts which contains comments in laravel
- Check if Relationship Method Exists in Laravel
- Return view from route Laravel
- Get today records in Laravel
- Laravel 5.4 save data to database
- Save or update pivot table data with additional column in Laravel
- Create a record if not exist in laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to get last record from object collection in laravel
- How to validate URL with https using regex in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Define variable and use in Laravel controller method
- Get last week data in Laravel
- Redirect to previous page or url in laravel
- Use withCount() to get total number of records with relationship
- Return redirect laravel not working
- How to get CSRF token in laravel controller
- Automatically remove records using Prunable trait in Laravel