【问题标题】:Composer View in laravellaravel 中的作曲家视图
【发布时间】:2016-10-14 21:20:27
【问题描述】:

我正在尝试在 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

有什么想法吗?

【问题讨论】:

    标签: php laravel nginx laravel-5.1


    【解决方案1】:

    解决办法是:

    $view->currentModelName;
    

    【讨论】:

      猜你喜欢
      • 2015-06-14
      • 2016-04-26
      • 2018-09-28
      • 2014-12-01
      • 2014-07-07
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      相关资源
      最近更新 更多