我想在Laravel中缓存查询。
public function index()
{
if (Redis::exists('products')) {
$products = json_decode(Redis::get('products'));
} else {
$products = Product::with('variations.stock')->get();
Redis::set('products', json_encode($products));
}
return ProductIndexResource::collection($products);
}
但出现以下错误:
Symfony\Component\Debug\Exception\FatalThrowableError
Call to a member function first() on array
为什么?