phplaravellaravel-pagination

Missing Bootstrap pagination page numbers in Laravel 8


I copied the table from blade file B which pagination is working fine to blade file A. But the pagination is not working on Blade file A. It does have 10 results shown, but the page number navigation is missing.

Here's a screenshot for reference: Missing page numbers

Here is my code:

Blade file A

<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12">
        <table class="table table-bordered">
            <tr>
                <th></th>
                <th>No</th>
                <th>Zone</th>
                <th>Code</th>
                <th>Description</th>
            </tr>
            @foreach ($items as $key => $item)
            <tr>
                <td>{{ Form::checkbox('item[]', $item->id, false, array('class' => 'name')) }}</td>
                <td>{{ $loop->index+1 }}</td>
                <td>{{ $item->zone }}</td>
                <td>{{ $item->code }}</td>
                <td>{{ $item->description }}</td>
            </tr>
            @endforeach
        </table>
    </div>
</div>

Blade file B:

<table class="table table-bordered">
  <tr>
     <th>No</th>
     <th>Zone</th>
     <th>Code</th>
     <th>Description</th>
     <th width="280px">Action</th>
  </tr>
    @foreach ($items as $key => $item)
    <tr>
        <td>{{ ++$i }}</td>
        <td>{{ $item->zone }}</td>
        <td>{{ $item->code }}</td>
        <td>{{ $item->description }}</td>
        <td>
            {{-- <a class="btn btn-info" href="{{ route('items.show',$item->id) }}">Show</a> --}}
            @can('item-edit')
                <a class="btn btn-primary" href="{{ route('items.edit',$item->id) }}">Edit</a>
            @endcan
            @can('item-delete')
                {!! Form::open(['method' => 'DELETE','route' => ['items.destroy', $item->id],'style'=>'display:inline']) !!}
                    {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
                {!! Form::close() !!}
            @endcan
        </td>
    </tr>
    @endforeach
</table>

Controller A:

public function create(Request $request)
{
    $items = Item::paginate(10);
    $sites = Site::get(["name", "id"])->all();
    // $states = State::all();
    // $cities = City::where("state_id",14)->get(["name", "id"]);
    return view('services.create', compact('sites', 'items'))
        ->with('i', ($request->input('page', 1) - 1) * 5);
}

Controller B:

public function index(Request $request)
{
    $items = Item::orderBy('id', 'DESC')->paginate(10);
    return view('items.index', compact('items'))
        ->with('i', ($request->input('page', 1) - 1) * 5);
}

Solution

  • This is the problem with the new Version laravel. In your App\Providers\AppServiceProvider class, you need to add the code below inside the boot() function to support the bootstrap paginator.

    use Illuminate\Pagination\Paginator;
    
    public function boot()
    {
         Paginator::useBootstrap();
    }
    

    At the end of Blade </table> please add this.

    <div class="d-felx justify-content-center">
         {{ $items->links() }}
    </div>