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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community