我看到了这个问题。我有类似的问题,但它不起作用。Laravel 4 公共功能。
我有一个视图编辑器,其中包含基本布局中的一些代码。这是我的作曲家:
View::composer(array('common.menu_addition','common.base_errors','common.view_special'), function($view)
{
if(Auth::check()) {
$roles = Auth::user()->type;
if ($roles == '5') {
$view->with('roles', $roles);
} else {
return Redirect::to('news/index');
}
}
});
当我没有登录时,它可以完美运行。但是我的视图作曲家文件之一是这样的:
<div class="pull-right">
@if (Auth::check())
@if ($roles == 5)
<ul class="nav">
<li>
<a href="{{ URL::to('admin/dash') }}">
<i class="icon-eye-open">
</i>
<strong>
Admin Dashboard
</strong>
</a>
</li>
</ul>
@endif
@endif
</div>
当我登录时,它不会显示任何网站。它只是Undefined variable: roles
在那个视图作曲家文件中说。