I’m trying to paginate data in laravel using paginate().
Got error ‘Call to a member function paginate() on array’
My code
public function view()
{
$sql = DB::select("select * from web_v2.web_mnp('','','','','','','','','','','','','1')")->paginate(10);
$user = User::paginate(10);
return Inertia::render('Mnp/View', [
'sql' => $sql,
'user'=> $user
]);
}
It works for user but gives error on $sql. I need to use postgresql function here, DO NOT recommend me changing to eloquent or normal sql. I’m currently using limit/offset to do pagination manually but want to change to laravel built in function paginate(). The ” inside are for parameters I cleared them for less code to show. Attached screenshot of how data looks by running this code.
public function view()
{
$sql = DB::select("select * from web_v2.web_mnp('','','','','','','','','','','','','1')");
$user = User::get();
return Inertia::render('Mnp/View', [
'sql' => $sql,
'user'=> $user
]);
}
It shows object but with paginate() it says it’s an array which confuses me.