Sib*_*ain 5 laravel blade laravel-4
我有一些刀片模板文件,我希望根据会话中存储的当前用户的权限动态地包含在我的视图中.以下是我写的代码:
@foreach (Config::get('constants.tiles') as $tile)
@if (Session::get('currentUser')->get('permissions')[$tile]['read'] == 1)
@include('dashboard.tiles.' . $tile)
@endif
@endforeach
Run Code Online (Sandbox Code Playgroud)
Blade不允许我将常量字符串与变量$ tile的值连接起来.但我想实现这个功能.任何有关这方面的帮助将受到高度赞赏.
小智 11
您无法在刀片模板命令中连接字符串.因此,您可以将包含的文件名分配到php变量中,然后将其传递给blade template命令.
@foreach (Config::get('constants.tiles') as $tile)
@if (Session::get('currentUser')->get('permissions')[$tile]['read'] == 1)
<?php $file_name = 'dashboard.tiles.' . $tile; ?>
@include($file_name)
@endif
@endforeach
Run Code Online (Sandbox Code Playgroud)
Laravel 5.4 - 动态包含字符串连接在刀片模板中工作
@foreach (Config::get('constants.tiles') as $tile)
@if (Session::get('currentUser')->get('permissions')[$tile]['read'] == 1)
@include('dashboard.tiles.' . $tile)
@endif
@endforeach
Run Code Online (Sandbox Code Playgroud)