是否可以使用变量作为对Laravel Blade指令的调用?
对于我的菜单系统,我已经定义了一个组件,我希望能够设置组件中链接的可见性。我创建了许多Blade指令(user-follows
,staff
,admin
等)来检查用户的角色。
我的组件定义如下:
client
我想做的是:
@component('components.primaryMenu', [
'items' => [
[
'route' => route('some.uri'),
'visibility' => ['staff', 'client'],
'label' => 'Item 1',
],
[
'route' => route('another.uri'),
'visibility' => ['everyone'],
'label' => 'Item 2',
],
]
])@endcomponent
当我运行此代码时,我得到<ul class="nav">
@foreach($items as $item)
@foreach($item['visibility'] as $visibility)
@{{ $visibility }} // Should interpolate to @staff / @client
// Link stuff in here
@end{{ $visibility }} // Should interpolate to @endstaff / @endclient
@endforeach
@endforeach
</ul>
。我猜是因为"Invalid argument supplied for foreach()"
声明正在抛弃解析器。
My Blade指令在服务提供商中定义,如下所示:
@{{ $visibility }}