public function __construct() { parent::__construct(); if (!Cache::has('categories')) { //如果分类缓存不存在 DataCache::cacheCategories(); } $categories = Cache::get('categories'); //使用视图组件,传入头部导航数据 view()->composer('widgets.bootstrapCategory', function ($view) use($categories) { $view->with('categories', $categories); }); view()->composer('widgets.bootstrapHeader', function ($view) { $topPage = Content::page()->take(3)->get(); //最多取得3个单页,以免撑爆导航栏 $view->with('topPage', $topPage); }); }