Laravel function not reading the $id

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);
});
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ur2QSH
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time