Level 6
I'm not sure that work. Do you need to do a raw query to get that result?
How do I paginate a raw call from database?
public function index()
{
$data = DB::select(DB::raw('select * from categories', [1]));
$products = DB::select(DB::raw('select * from products', [1]))->paginate(8);
dd($products);
return view('products.products', ['data' => $data], ['products' => $products]);
}
I tried this, but it returns "Call to a member function paginate() on array"
I'm not sure why you'd not want to use Eloquent, but anyway.
You are executing and immediately returning the results of the query, thus having an array at your disposal which in turn results into a paginate() call on that array. The error you receive perfectly describes your mistake.
The paginate method lives on the \Illuminate\Database\Query\Builder class, so you'll have to use that in order to leverage pagination:
DB::table('products')->paginate(8)
Please or to participate in this conversation.