In my web application I have added the cache method. But the problem is its not reading the specified $id which is passing in the function. So that its throwing error like :
ErrorException: Undefined variable: id
What to do if anyone suggest any answers will be helpful.
Here is the code ->
public function relatedstory($id)
    {
        $key = $id;
        $cacheKey = $this->getCacheKey($key);
        return cache()->remember($cacheKey, Carbon::now()->addDay(1), function ()
        {
            $story = $this->_story->findOrFail($id);
            $tags = $story->tags->random(1)->pluck('tag_id');
            $storyIds = StoryTagItem::whereTagId($tags)->get()->random(4)->pluck('story_tag_id');
            $relatedStory = [];
            foreach($storyIds as $storyId)
            {
                array_push($relatedStory, $this->_story->findOrFail($storyId));
            }
            return StoryListResource::collection($relatedStory);
        });
    }
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire