Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix laravel 8 UI paginate problem?

Tags:

I had a problem while trying out the recently released laravel 8, I'm trying to find out what the changes are and how it works. When I did that I had a problem with the paginate laravel 8 UI getting messy and somehow it happened. Is there anyone who can help me? or have experienced the same thing?

Like this the view I got in laravel 8 Laravel 8 paginate UI

and this is the code I use "Index.blade.php"

@extends('layouts.app')  @section('title', 'Post')  @section('contents')      <div class="container">         <div class="row">             @foreach ($posts as $post)                 <div class="col-md-4 mb-4">                     <div class="row">                         <div class="card mb-4">                             <div class="card-header">                                 {{ $post->title }}                             </div>                             <div class="card-body">                                 {{ $post->body }}                             </div>                             <div class="card-footer">                                 {{ $post->created_at->diffForHumans() }}                             </div>                         </div>                     </div>                 </div>             @endforeach         </div>         <div class="d-felx justify-content-center">              {{ $posts->links() }}          </div>     </div>  @endsection 

the code I use for PostController

<?php  namespace App\Http\Controllers;  use App\Models\Posts; use Illuminate\Http\Request;  class PostsController extends Controller {     public function index()     {         $posts = Posts::latest()->paginate(6);         // dd($post);         return view('post.index', compact('posts'));     } } 
like image 643
Habi nata Avatar asked Sep 11 '20 03:09

Habi nata


People also ask

How can I use pagination in Laravel 8?

To perform pagination in laravel, you just have to use the paginate () function instead of all () or get() functions as used in maximum time. Paginate method takes a number as a parameter. It defines how much data you want to show on one page or section.

How can I get pagination page numbers in Laravel?

In your case you can use $articles->links() in your view to generate the pagination navigation buttons. But if you want to manually set the page then you can do this. $articles = Articles::paginate(5, ['*'], 'page', $pageNumber); The default paginate method takes the following parameters.


Video Answer


2 Answers

just make sure you have this in your AppServiceProvider.

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

and you're good to go.

like image 102
Manoj Avatar answered Sep 27 '22 16:09

Manoj


I tried doing adding the Paginator::useBootstrap(); in the AppServiceProvider.php but it didn't work.

But this worked:

// Directly in your blade file $posts->links('pagination::bootstrap-4') 
like image 39
Taylor Avatar answered Sep 27 '22 15:09

Taylor