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

Updated 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