Method Illuminate\Database\Eloquent\Collection::appends does not exist

Created at 03-Sep-2021 , By samar

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

    use App\Http\Controllers\HomeController;
    Route::get('/pagination-with-query-string', [HomeController::class, 'getRecords']);
    use App\Models\User;
    public function getRecords(){
        $users = User::select('*')->paginate(10);
        $users = $users->appends(['keyword'=>'value']);
        return view('search')->with(['users'=>$users]);
        @foreach ($users as $user)
            <td> {{ $user->name }}  </td>
    {{ $users->links() }}

    You can add query string to URL in laravel using appends() method in controller file. 

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

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.