Support the ongoing development of Laravel.io →
Cache Views Blade
Last updated 2 years ago.
0

If I'm understanding you correctly, and you want to pull some data in a view or view partial and then cache the results, I might suggest a view composer:

http://laravel.com/docs/5.0/views#view-composers

I did something very similar for a menu that was dynamically stored in the database and looked something like this:

public function compose(View $view)
{
    $menus = \Cache::remember('menus', 60, function()
    {
        return \DB::table('menus')->get();
    });
    return $view->with('menus', $menus);
}

This will also give you the $menus object and all column names available to all views, that will only run the query one time and then cache it. You could cache that for as long as your need, or just use the rememberForever method, and then you wouldn't have to put in a time argument.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ghost202 ghost202 Joined 8 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.