在{{}} laravel blade set上为{url}设置{{}}

时间:2017-09-22 03:32:53

标签: php laravel-5.2 laravel-blade

如何在{{}}上设置{{}},我已经测试过,但始终是错误

这是我的代码:

  

PHP

      $roles = DB::table('users')->where('id','=',Auth::user()->id)->pluck('role');
      $role = $roles[0];
      $removekoma = str_replace(",","",$role);
      $arr1 = str_split($removekoma);
      $one   = array('0','1', '2', '3','4','5');
      $two   = array('Admin', 'Compiler', 'Evaluator NKK/NKD', 'Evaluator NKU', 'Facilitator', 'Bisiness User');
      $three = array('/admin','/compiler', '/evaluatornkd', '/evaluatornku','/facilitator','/kpi');
  

刀片

     <ul class="nav navbar-nav">
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="fa fa-chevron-down"></span></a>
        <ul class="dropdown-menu" role="menu">
           @foreach($arr1 as $drop) 
           <li><a href="{{ url('({{$url= str_replace($one, $three, $drop)}}) ') }}">{{$name= str_replace($one, $two, $drop)}}</a>
           @endforeach 
        </ul>
      </li>
    </ul>

1 个答案:

答案 0 :(得分:1)

您可以像这样{{ url($url) }}

设置网址
<ul class="nav navbar-nav">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="fa fa-chevron-down"></span></a>
            <ul class="dropdown-menu" role="menu">
               @foreach($arr1 as $drop) 
               @php $url= str_replace($one, $three, $drop); @endphp
               <li><a href="{{ url($url) }}">{{str_replace($one, $two, $drop)}}</a>
               @endforeach 
            </ul>
          </li>
        </ul>