Laravel Pagination

Add in Controller

In this example the we need to pass only digit how many records need to find on same page. In this case, let's specify that we would like to display 5 items per page:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class BlogController extends Controller
{
    public function index()
    {
        $blog = DB::table('blog')->paginate(5);

        return view('blog', ['data' => $blog]);
    }
}

Now view part within blog.blade.php

<div class="container">
    @foreach ($data as $blogs)
        {{ $blogs->title }}
    @endforeach
</div>

{{ $data->links() }}
Leave a Comment