如何从 Laravel 视图中的缓存中检索项目?

How to retrieve items from the cache in view in Laravel?

我在 Laravel 5.5 cache in Service Provider 中存储了一些数据,如下所示:

class DataServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $user = Cache::rememberForever('user', function () {
            return array('name' => 'jack', 'age' => 25);
        });
    }

    public function register()
    {
        //
    }
}

我通过以下方式从 controller 的缓存中检索项目:

  $user= Cache::get('user');

但我需要检索 views (blade) 中的 cache 项,我如何在 views (blade) 中直接 访问它们(不将缓存作为变量传递)? 我只想在 cache 中存储一次数据,然后在我的应用程序中随处访问它 ,无需更多步骤,这可能吗?

使用cache helper:

{{ cache('user')['name'] }}

缓存门面: {{ Cache::get('user')['name'] }}
缓存助手: {{ cache()->get('user')['name'] }}{{ cache('user')['name'] }}

我会这样做

@php 
    $user = Cache::get(“user”);
@endphp

 {{ $user[“name”]; }}