Your are returning an array that has been converted to the default php stdObject through the json encoding/decoding. stdObject doesn't have a render method.
Dec 3, 2019
8
Level 11
Laravel Pagination render()
Hi Guys, In my project, I'm getting this error
ErrorException (E_ERROR)
Call to undefined method stdClass::render() (View:
Where I'm using custom pagination where After combining two objects in my code applying pagination. here is my pagination code
public function paginateWithoutKey($items, $perPage = 15, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
$lap = new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
$res = [
'current_page' => $lap->currentPage(),
'data' => $lap->values(),
'first_page_url' => $lap->url(1),
'from' => $lap->firstItem(),
'last_page' => $lap->lastPage(),
'last_page_url' => $lap->url($lap->lastPage()),
'next_page_url' => $lap->nextPageUrl(),
'per_page' => $lap->perPage(),
'prev_page_url' => $lap->previousPageUrl(),
'to' => $lap->lastItem(),
'total' => $lap->total(),
];
return json_decode(json_encode($res));
}
I'm looping data in blade file and everything working except page links {{ $data->render() }}. can anyone help me on this i.e. how to resolve this issue. Thanks in advance.
Level 75
See my last answer here https://laracasts.com/discuss/channels/laravel/next-previous-functionality-in-single-page-view-and-going-to-next-and-previous-item-when-i-want
It covers paginating a collection which is what you will probably want.
Please or to participate in this conversation.