1

This is my controller file's index function

 public function index()
        {
            $projects = Projects::All()->paginate( 5 );
            return view('projects.index')->with('projects', $projects);
        }

And, This is my blade file's pagination code

@foreach ($projects as $project)

{{ $project->links('pagination::tailwind') }}

@endforeach

But, Still, there's an error, that is saying

BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::paginate does not exist. 
James Z
  • 12,209
  • 10
  • 24
  • 44
  • 1
    $projects = Projects::paginate( 5 ); – Garry Jan 21 '22 at 16:11
  • 1
    you need to call the ```paginate``` method from query. But ```all``` method will return a collection. So thats the reason you are getting the error ``` $projects = Projects::query()->paginate( 5 ); ``` will fix the issue – ManojKiran A Jan 21 '22 at 18:04

1 Answers1

0

You have a typo. This is not correct:

{{ $project->links('pagination::tailwind') }}

Error 1: You are missing a 's':

{{ $projects->links() }}

Error 2: You do not have to put your links in the loop but outside the loop. normaly after the loop.

@foreach($records as $record)
{{ $record->field }}
@endforeach
{{ $records->links() }}

Suggestion: I prefer to tell laravel which paginator I am using in this file: App/Providers/AppServiceProvider.php

public function boot()
{
    Paginator::useBootstrap(); //bootstrap in this case
}

For tailwind, there is no need to specify anything, since it is the default.

Dharman
  • 30,962
  • 25
  • 85
  • 135
M. Saba
  • 34
  • 4
  • https://laravel.com/docs/8.x/pagination#customizing-the-pagination-view – M. Saba Jan 21 '22 at 18:01
  • Your solutions for "Error 1" and "Error 2" seems to conflict with each other. But none of this will solve the error message mentioned in the question, which was solved in comments 2 hours ago. – miken32 Jan 21 '22 at 18:48