我正在尝试在laravel 5.1中创建一个作曲家视图
这是我的AppServiceProvider:
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
view()->composer('layouts.dashboard', function ($view) {
dd($view);
}
);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
它给了我:
View {#486 ▼
#factory: Factory {#107 ▶}
#engine: CompilerEngine {#382 ▶}
#view: "layouts.dashboard"
#data: array:9 [▼
"obLevel" => 0
"__env" => Factory {#107 ▶}
"app" => Application {#2 ▶}
"errors" => ViewErrorBag {#322 ▶}
"currentModelName" => "Torneo"
"modelPlural" => "Torneos"
"levels" => Collection {#383 ▶}
"categories" => Collection {#390 ▶}
"tournament" => Tournament {#379 ▶}
]
#path: " /Users/Julien/laravel/resources/views/layouts/dashboard.blade.php"
}
现在,我需要访问currentModelName。
我尝试过$view->data
,$view->data->currentModelName
但还是会返回null
有任何想法吗?
解决方法是:
$view->currentModelName;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句