Method Illuminate\Database\Eloquent\Collection::appends does not exist
Method IlluminateDatabaseEloquentCollection::appends does not exist
In this article, we will see how to solve "Method IlluminateDatabaseEloquentCollection::appends does not exist".
Method Illuminate\Database\Eloquent\Collection::appends does not exist. It found this error in my controller file because I did not used paginate() method on collection. Add paginate method on collection object before calling the appends method in controller to avoid error in laravel 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.
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
- Comment .env file in laravel
- Target class [HomeController] does not exist
- How to add a key value pair to existing array in laravel
- 419 page expired error in Laravel
- How to add foreign key in laravel using migration
- Display data in table using foreach in Laravel
- Update record after find method in lavavel
- How to add columns in existing table using migration in laravel
- How to update record after save method in Laravel
- How to start websocket server in laravel
- Redirect to previous page or url in laravel
- OrderBy on Eloquent relationships method in Laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Seed database using SQL file in Laravel
- Return view from route Laravel
- How to get single column value in laravel
- How to get tomorrow and yesterday date in laravel
- How to Get records between two dates in Laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to insert dynamic value to additional column in pivot table in laravel
- Insert values in pivot table dynamically in laravel
- Conditional validation in laravel
- Where to use whereNotNull eloquent in laravel
- Laravel 10 starter app using breeze on live server
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]