我正在拉威尔建立一个页面生成器。前端呈现添加到“我的管理”页面中的“块”。我想,确保这些块在我需要的地方都可用的最好方法是将它们加载到一个视图生成器中,这非常有效;
View::composer('*', function ($view) {
$blocks = Page::where('url', url()->current());
return view()->with(['blocks', $blocks]);
});
但是,这会尝试为前端路由和管理路由加载块。有没有办法确保它们只在前端的路线上装载?
我把我的路线分割成这样的文件;
$this->mapAdminRoutes();
protected function mapAdminRoutes()
{
Route::prefix('admin')
->middleware('admin')
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
}
我在谷歌搜索时确实发现了这个问题
Binding a Laravel service provider on specific routes