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.
Displaying Pagination Results
In category->index.blade.php
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