PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] Laravel pagination not working with tailwindcss

 February 16, 2022     backend, laravel, pagination, php, tailwind-css     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing