Issue
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.
Solution
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.
Answered By - M. Saba
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.