Laravel : pagination with DB in laravel

In this tutorial learn how to display records using pagination with DB/database in laravel.

There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent query.


<?php

namespace App\Http\Controllers;

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

class CategoryController extends Controller
{
    /**
     * Show all of the users for the application.
     *
     * @return Response
     */
    public function index()
    {
        $categories = DB::table('categories')->paginate(15);

        return view('category.index', ['categories' => $categories]);
    }
}

Displaying Pagination Results

In  category->index.blade.php


 @foreach($categories  as $index =>  $category)
                <tr>
                    <td>{{$index+1}}</td>
                    <td>{{$category->cat_name}}</td>
                </tr>
   @endforeach

  {{ $categories->links() }}

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...