Laravel remember cache

  caching, laravel, php

I’m trying to remember cache for 6 minute on home page but it’s errors.
I want 10 parameters in one key ( homepage-data )
so what i’m doing wrong?

public function index()
{
    $rememberKey = 'homepage-data';
    $minutes = 600;
    Cache::remember($rememberKey, $minutes, function () {

        $breakingNews = BreakingNews::published();
        $rightSlider = Article::rightSlider()->take(20)->get();
        $leftSlider = Article::leftSlider()->take(9)->get();
        $shows = Show::publishedOrderShows()->take(10)->get();
        $blogs = Article::allBlogs()->take(12)->get();
        $latestNews = Article::latestNews()->whereNotIn('id', $rightSlider->pluck('id')->merge($leftSlider->pluck('id')))->take(5)->get();
        $otherNews = Article::otherNews()->whereNotIn('id', $rightSlider->pluck('id')->merge($leftSlider->pluck('id')))->take(2)->get();
        $otherNewsDown = Article::otherNews()->whereNotIn('id', $rightSlider->pluck('id')->merge($leftSlider->pluck('id'))->merge($otherNews->pluck('id')))->take(8)->get();
        $analyticNews = Article::allAnalytics()->take(4)->get();
        $populars = Article::popular()->take(10)->get();
        $quizzes = Quizze::quizOrderBy();

        return view('pages/home-page')->with([
            'breakingNews' => $breakingNews, 'rightSlider' => $rightSlider,
            'leftSlider' => $leftSlider, 'shows' => $shows, 'blogs' => $blogs, 'latestNews' => $latestNews,
            'otherNews' => $otherNews, 'otherNewsDown' => $otherNewsDown, 'analyticNews' => $analyticNews,
            'populars' => $populars, 'quizzes' => $quizzes
        ]);
    });
}

I’m getting Serialization of ‘Closure’ is not allowed error.

Source: Laravel

Leave a Reply