Level 70
Check this discussion...
This is my controller.
$default= DB::table('products')
........
->paginate(5)->toArray();
$notDefault= DB::table('products')
.......
->paginate(5)->toArray();
$lists = array_merge($default, $notDefault);
$currentPage = LengthAwarePaginator::resolveCurrentPage();
// Create a new Laravel collection from the array data
$col = new Collection($lists);
// Define how many items we want to be visible in each page
$perPage = 5;
// Slice the collection to get the items to display in current page
$currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
// Create our paginator and pass it to the view
$paginatedItems= new LengthAwarePaginator($currentPageSearchResults , count($col), $perPage);
// set url path for generted links
$paginatedItems->setPath($request->url());
return View::make('listing',['lists' => $paginatedItems],compact('id_p'));
This is my route.
Route::get('listing/{id}', ['uses' => 'Controller@listing', 'as' => 'prod_listing']);
This is my view
@foreach($lists as $list)
........
@endforeach
{{$lists ->link()}}
I tried this but get "Trying to get property of non-object" error. Anyone can tell me what is the problem? How can i do pagination with array? Thanks.
Please or to participate in this conversation.