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 insert dynamic value to additional column in pivot table in laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- PhpMyAdmin - Error The mysqli extension is missing
- How to get IP address in laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Composer\Exception\NoSslException
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Use withCount() to get total number of records with relationship
- Display option of select as selected with blade directive Laravel
- How to get single column value in laravel
- How to upload files to amazon s3 bucket using Laravel
- Update email with unique validation in laravel
- How to insert multiple rows in mysql using loop in laravel?
- Laravel 9 pagination with search filter
- How to create event and listener in laravel ?
- InRandomOrder() method with example in laravel
- Redirect to another view from controller in laravel
- Laravel save object to database
- How to get all posts which contains comments in laravel
- Laravel specific table Migration
- Page loader in laravel
- Seed database using SQL file in Laravel
- Rename Pivot Table in Laravel
- Where to use whereNotNull eloquent in laravel