jcadima
9/2/2017 - 1:48 PM

Laravel Pagination

Laravel Pagination


https://laravel.com/docs/5.4/pagination
<?php

public function index()
{
  // get parameter id if its present in url:
  // admin
  // admin/4
    $videos = ( request()->id ) 
        ? Video::where('category_id', '=', request()->id )->paginate(10)
        : Video::latest('created_at')->paginate(20) ;

    // $videos = Video::latest('created_at')->paginate(20) ;
    return view('admin.dashboard')->with('videos', $videos)
                                  ->with('categories', Category::all() ) ;
}