Reputation:
I need to return a json with all products and stores.
I tried this
$products = $products->paginate(20);
$stores=$this->getStores();
return ['product'=> $products, 'stores' =>$stores];
but $products returns empty. (If i run "return $products" it works fine)
Is there something i can do? Why laravel doesn't let me have the pagination in an array?
Upvotes: 1
Views: 103
Reputation:
Solution:
return ['product'=> $products->toArray(), 'stores' =>$stores];
or
return Response::json(
array(
'products' => $products->toArray(),
'stores' => $stores,
), 200
);
Upvotes: 1
Reputation: 261
You could do something like this :
return Response::json(
array(
'products' => $products,
'stores' => $stores,
), 200
);
You also need to 'use' the Response facade:
use Illuminate\Support\Facades\Response;
Upvotes: 3