Laravel

How to fix Laravel 8 blog post UI paginate problem?

There are several ways to paginate items like for use in blog list. The simplest is by using the paginate method on the query builder or an Eloquent model. 

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?

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


code used 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'));
    }
}
If you are using Bootstrap add this code in your  "app/Providers/AppServiceProvider"

use Illuminate\Pagination\Paginator;

public function boot()
{
     Paginator::useBootstrap();
}
and you're good to go.


If you tried doing adding the Paginator::useBootstrap(); in the AppServiceProvider.php and if it  didn't work try below directly in your blade file.

// Directly in your blade file
$posts->links('pagination::bootstrap-4')

About Zaishan

0 comments:

Post a Comment

Powered by Blogger.