3

So, I'm creating a project using laravel and tailwind. After using the paginate() method and then this code in the view

@if ($posts->count())
                @foreach ($posts as $post)
                    <div class="mb-4">
                        <a class="font-bold" href="">{{ $post->user->name }}</a> <span
                            class="text-gray-600 text-sm">{{ $post->created_at->diffForHumans() }}</span>

                        <p class="mb-2">{{ $post->description }}</p>
                    </div>

                @endforeach
                {{ $posts->links() }} (this line to create the link to other pages is not working properly)
            @else
                <p>There are no posts</p>
            @endif 

The pagination design was a little bizarre. Going to the next and previous page is working correctly. Website

5 Answers5

5

I had the same problem. Wasn't able to fix it but found a workaround by using:

php artisan vendor:publish --tag=laravel-pagination

As described here: https://laravel.com/docs/8.x/pagination#customizing-the-pagination-view

The outputted resources/views/vendor/pagination/tailwind.blade.php file did have the correct css and looked good.

wadapatja
  • 51
  • 2
1

You can install npm i tailwindcss-plugins -D

Then register the plugin in your tailwind configuration.

plugins: [
    require('tailwindcss-plugins/pagination')({
        /* ... */
    }),
],

And then you can use this in your blade:

{{ $items->links() }}

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
0

I also had the same problem and was able to solve it by using this command:

php artisan vendor:publish --tag=laravel-pagination
ouflak
  • 2,458
  • 10
  • 44
  • 49
Suleman
  • 23
  • 1
  • 7
0

Make sure that if you publish the vendor view with either:

artisan vendor:publish

and selecting the 'laravel-pagination' tag or using the command argument:

artisan vendor:publish --tag=laravel-pagination

That the resulting published view files are included in your tailwind.config.js.

For example:

/** @type {import('tailwindcss').Config} */
module.exports = {
    darkMode: 'class',
    content: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
        "./resources/**/*.vue",
        "./resources/views/vendor/pagination/*.blade.php",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
}

I found that without this, the tailwind styles weren't applied. However, I am not sure why since the ./resources/**/*.blade.php pattern should have picked them up from what I have read.

E.G: this answer

Double Asterisk (**) matches zero or more characters across multiple segments. It is used for globbing files that are in nested directories.

Example: Tests/**/*.js

Here, the file selecting will be restricted to the Tests directory. The glob will match the files such as Tests/HelloWorld.js, Tests/UI/HelloWorld.js, Tests/UI/Feature1/HelloWorld.js.

0

How to use tailwind with laravel and make it work is written in the official documentation - read!

Additionally! Tailwind in Laravel is used for pagination by default. If you need to change the styles used, for example, to Bootstrap, you can easily do this by writing in next code:

app/Providers/AppServiceProvider.php

// ...
public function boot(): void
{
    \Illuminate\Pagination\Paginator::useBootstrapFive();
}
// ...

official documentation