
How to pass query string with pagination in laravel
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
Answers 1
-
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() }}
0You 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
Random Code Snippet Queries: Laravel
- There are no commands defined in the "route:" namespace
- How to get path from current URL in Laravel
- Create model with migration and seeder
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Always load the relationship data with eager loading in Laravel
- Laravel file size validation not working
- Get last year created records in Laravel
- Cannot end a section without first starting one
- Delete file from amazon s3 bucket using Laravel
- How to add active class to menu item in laravel
- How to create belongstomany relation using custom name on custom pivot table
- Laravel 9 route group with controller
- Laravel upload file with original file name
- Extra Filter Query on Relationships in Laravel
- JQuery each loop on json response after ajax in laravel
- Php artisan make model, factory, migration and controller in single command
- Display data in table using foreach in Laravel
- How to generate .env file for laravel?
- How to add class to tr in table using foreach in laravel
- Get id of last inserted record in laravel
- Trying to access array offset on value of type null error in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Route prefix with auth middleware in laravel
- Call to a member function pluck() on null
- How to increment column value of table in Laravel