laravel pagination links not clicking

Viewed 26

Appreciate help on this. The pagination links are not working. The page renders correctly but although the links shows as links, when clicked does not work. My structure is as follows: If I remove the following references in the class file the pagination works but it is not formatted correctly.

use Livewire\WithPagination; use WithPagination;

Class File: AdminDashboardDirectoryCategoryComponent.php

<?php

namespace App\Http\Livewire\Admin;

use App\Models\DirectoryCategory;
use Livewire\Component;
use Livewire\WithPagination;

class AdminDashboardDirectoryCategoryComponent extends Component
{
    use WithPagination;

    public function render()
    {
        $dcategories = DirectoryCategory::paginate(9);
        return view('livewire.admin.admin-dashboard-directory-category-component',['dcategories'=>$dcategories])->layout('frontend_layout.index2');
    }
}

View File: admin-dashboard-directory-category-component.blade.php

style>
    nav svg {
    height: 20px;
    }
    nav .hidden {
    display: block !important;
    }
</style>

        <section class="content-central">
            <div class="content_info">
                <div class="paddings-mini">
                    <div class="container">
                        <div class="row portfolioContainer">
                            <div class="col-md-12">
                                <table class="table table-striped tester1">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Image</th>
                                            <th>Group</th>
                                            <th>Title</th>
                                            <th>Slug</th>
                                          
                                    </thead>
                                    <tbody>
                                        @foreach($dcategories as $dcategory)
                                            <tr>
                                                <td>{{$dcategory->id}}</td>
                                                <td><img src="{{asset('frontend/assets/images/dir_categories')}}/{{$dcategory->category_image}}" width="60" /></td>
                                                <td>{{$dcategory->category_group}}</td>
                                                <td>{{$dcategory->category_title}}</td>
                                                <td>{{$dcategory->category_slug}}</td>
                                          
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>

                                {{$dcategories->links()}}
                            
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
</body>

</html>
2 Answers

https://laravel-livewire.com/docs/2.x/pagination

When using either method, instead of anchor tags in your pagination component, you should use wire:click handlers with the following methods:

nextPage to navigate to the next page

previousPage to navigate to the previous page

gotoPage($page) to navigate to a specific page.

You are missing these methods.

  1. You can add Using The Bootstrap Pagination Theme.

    protected $paginationTheme = 'bootstrap';

  2. Call all databases.

    $dcategories = DirectoryCategory::all()->paginate(9);

Related