Laravel pagination links with query string
Laravel pagination links with query string
We will use programming in this lesson to attempt to solve the "Laravel pagination links with query string".
You can pass query string to pagination link by appends() method to display the filtered data with pagination.-
Pagination link with query string in laravel view
{{ $users->appends(['keyword' => request()->get('keyword')])->links() }}
You can displayed filtered records with query string using pagination.
On click pagination link, It will create url like http://localhost:8000/search?keyword=value&page=2 which helps you to display the filttered data with pagination.
-
Pass 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(['keyword'=>'value']); 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 query string to URL in laravel using appends() method in controller file.
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
- Docker important commands to run laravel application with docker
- Call to undefined method Illuminate\Support\Facades\Request::all()
- How to get route name on visit URL in laravel
- How to get all posts which contains comments in laravel
- First and last item of the array using foreach iteration in laravel blade
- Laravel change date format
- How to add columns in existing table using migration in laravel
- Laravel migration add foreign key to existing table
- How to get path from current URL in Laravel
- How to display user profile after login in laravel
- Get latest record by created at in Laravel
- Update last created record in Laravel
- How to get count of all records created at yesterday
- Ajax GET request in laravel
- How to get the random value form a specific column in laravel ?
- How to validate URL with https using regex in laravel
- Symlink(): No such file or directory
- How to get last month records in Laravel
- Conditional validation in laravel
- How to insert value to additional columns in pivot table in laravel
- How to make Copy or Duplicate table row in laravel
- On delete set foreign id column value null using migration in laravel 8
- How to add a key value pair to existing array in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- The Pusher library requires the PHP cURL module. Please ensure it is installed