1 year ago

how to laravel cache resources?

Posted 1 year ago by haizone

i have this list that i get from DB

$products = $category
return ProductIndexResource::collection($products);

now i get a collection of products for that category

how i can cache every product in the products collection that i get from the category products? somthing like that, with uniq if from every product

$product = Cache::remember('product-'.$product->id, 14400, function() use ($products){
        return ???;

this is my resources

    public function toArray($request)
    return [
        'name' => trim($this->name),
        'english_name' => $this->english_name,
        'slug' => $this->slugi,
        'model' => $this->model,
        'position' =>$this->position,
        'details' =>$this->details,
        'productoptions' =>$this->productoptions,

Please sign in or create an account to participate in this conversation.