Reputation: 949
I've stored some data in Laravel 5.5 cache in Service Provider as you can see in following:
class DataServiceProvider extends ServiceProvider
{
public function boot()
{
$user = Cache::rememberForever('user', function () {
return array('name' => 'jack', 'age' => 25);
});
}
public function register()
{
//
}
}
I retrieve items from the cache in controller
by this:
$user= Cache::get('user');
But I need to retrieve cache
items within views (blade)
, How can I access them directly in views (blade)
(without passing cache as variable)?
I just want to store data in cache
once, and access to it everywhere in my app with no more steps, is it possible?
Upvotes: 0
Views: 7134
Reputation: 646
I would do it like this
@php
$user = Cache::get(“user”);
@endphp
{{ $user[“name”]; }}
Upvotes: 0
Reputation: 192
Cache Facade: {{ Cache::get('user')['name'] }}
cache helper: {{ cache()->get('user')['name'] }}
or {{ cache('user')['name'] }}
Upvotes: 2