我试图在定义要呈现的 View 时根据变量集包含一些 View 。
这是我渲染 View 的时候:
switch (Auth::user()->role) {
case 'ADMINISTRADOR':
return View::make('admin');
break;
case 'CAPTURISTA':
return View::make('capturista');
break;
case 'GERENTE DE DEPARTAMENTO':
return View::make('gerente');
break;
case 'SUPERVISOR DE COMPRAS':
return View::make('supervisor', array('supervisor'=>true));
break;
case 'GERENTE ADMINISTRATIVO':
return View::make('administrativo');
break;
}
所以我尝试了很多东西来加载一些 View 仅 如果主管为真(最后是否根据我的代码设置)。
我试过的
@if(isset($supervisor))
@include('includes.boss.supervisor.delivers_modal')
@include('includes.boss.supervisor.prices_modal')
@include('includes.boss.supervisor.providers_modal')
@endif
@if({{isset($supervisor)}})
@include('includes.boss.supervisor.delivers_modal')
@include('includes.boss.supervisor.prices_modal')
@include('includes.boss.supervisor.providers_modal')
@endif
<?php if(isset($message)) : ?>
@section('message')
<p>hey all</p>
@endsection
<?php endif; ?>
我也尝试设置
supervisor
每个 View 的变量,自然是假和真。 @if($supervisor)
@include('includes.boss.supervisor.delivers_modal')
@include('includes.boss.supervisor.prices_modal')
@include('includes.boss.supervisor.providers_modal')
@endif
这些都不起作用,我应该如何实现它?
* 以防万一,我正在使用 session ...
最佳答案
从 Laravel 5.4 开始,您可以使用 @includeWhen
.如 docs 中所述:
Including Sub-Views
If you would like to
@include
a view depending on a given boolean condition, you may use the@includeWhen
directive:@includeWhen($boolean, 'view.name', ['some' => 'data'])
关于php - 如何使用 Laravel 在 Blade 中有条件地包含 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29478672/