Can you dd($widget) and check what was the output of the code?
assuming as like below pagination buttons should be,
{{ $pageWidget->articles->links() }}
i'm trying to paginate list of articles inside my app news page withen main query like this
public static function getPageWidgets($id, $lang)
{
$pageWidget = Cache::rememberForever('page-'.$id, function () use ($id,$lang) {
return Widget::with(
['wsubcats','buttons', 'content', 'content.linkedPage', 'content.linkedArticle','articles' => function ($query) use ($lang) {
$query->where('language', '=', $lang)->paginate(15);
}]
)
->where('page_id', '=', $id)
->orderBy('sorting', 'asc')
->get();
});
return $pageWidget;
}
in blade i need to show pagination btns so i'm doing this
{{ $widget->articles->links() }}
this is the error i'm getting
Method Illuminate\Database\Eloquent\Collection::links does not exist. (View: /Applications/MAMP/htdocs/resources/views/includes/dynamicList.blade.php) (View: /Applications/MAMP/htdocs/resources/views/includes/dynamicList.blade.php) (View: /Applications/MAMP/htdocs/resources/views/includes/dynamicList.blade.php)
any idea on how to paginate this type of query
You cannot paginate a nested relation.
You need to fetch the paginated collection as a separate variable and pass that to the view.
Please or to participate in this conversation.