php Laravel View Composer
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Laravel View Composer相关的知识,希望对你有一定的参考价值。
public function boot() {
view()->composer( 'layouts.master', function( View $view ) {
$ticketRoutes = [
'admin.tickets.index',
'admin.tickets.create',
'admin.tickets.update',
'admin.tickets.foruser'
];
$userRoutes = [
'admin.users.index',
'admin.users.create',
'admin.users.edit'
];
$clientRoutes = [
'admin.clients.index',
'clients.show'
];
$allRoutes = json_encode( array_merge( $ticketRoutes, $userRoutes, $clientRoutes ) );
$view->with( 'routeName', $this->currentRouteName() )
->with( 'ticketRoutes', $ticketRoutes )
->with( 'userRoutes', $userRoutes )
->with( 'clientRoutes', $clientRoutes )
->with( 'allRoutes', $allRoutes );
});
parent::boot();
}
<ul class="navbar-nav navbar-sidenav" id="sidebarLeft">
<li class="nav-item dropdown {{ ($routeName === 'admin.tickets.create') ? 'active' : '' }}">
<a class="nav-link dropdown-toggle" href="#">Tickets</a>
<div class="dropdown-menu">
<a class="dropdown-item">Child item 1...</a>
<a class="dropdown-item">Child item 2...</a>
<a class="dropdown-item">Child item 3...</a>
</div>
</li>
</ul>
<div class="breadcrumbs">
<span class="fa fa-home" aria-hidden="true"></span>
{{ \Illuminate\Support\Str::ucfirst( $routeName ) }}
</div>
// at the bottom, use @json to override Blade handling
<script>
var routeName = @json($routeName);
</script>
<script src="{{ asset('js/app.js') }}"></script>
</body>
以上是关于php Laravel View Composer的主要内容,如果未能解决你的问题,请参考以下文章
Laravel View Composer“使用未定义的常量”
Laravel,变量输出适用于 View::share 但不适用于 VIew::composer
Laravel View Composer 为每个视图复制 SQL 查询
带有存储库的 Laravel View Composer 不工作;
View Composer 在我的 Laravel 应用程序中不起作用
php laravel 框架搭建与运行