douzangdang2225
2017-12-01 06:08
浏览 70
已采纳

在laravel中带有foreach循环错误的elseif语句

I am trying to do a if else statement with a foreach loop but for some reason I am getting this error

Parse error: syntax error, unexpected 'elseif' (T_ELSEIF).

I know that this is a simple error but I can't seem to identify what is wrong here, did I do my code wrongly? Or is it something that need to be closed? (for the closing part, I have checked and I don't really see any problem with it) Can someone help me? Thanks a lot

profile.blade.php

@foreach($data as $value) 
  <tr> 
 @if($value->training_Status == 'No')
 <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
 @foreach($data1 as $value1)
  @elseif(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
 <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
  @endforeach
 @else 
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
 @endif 
 </tr> 
 @endforeach

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用foreach循环执行if else语句但由于某种原因我收到此错误

解析错误:语法错误,意外'elseif'(T_ELSEIF)。

我知道这是 一个简单的错误,但我似乎无法确定这里有什么问题,我是否错误地执行了我的代码? 还是需要关闭的东西? (对于结束部分,我已经检查过,我真的没有看到任何问题)有人可以帮助我吗? 非常感谢

profile.blade.php

  @foreach($ data as $ value)\  n&lt; tr&gt;  
 @if($ value-&gt; training_Status =='No')
&lt; th&gt;&lt; a href =“{{route('user.show',['id'=&gt; $ value-&gt  ; pi_id])}}“&gt;&lt; span style =”color:blue;“&gt; {{$ value-&gt; Name}}&lt; / span&gt;&lt; / a&gt;&lt; / th&gt; 
 @  foreach($ data1 as $ value1)
 @elseif(($ value1-&gt; blacklist =='Yes')&amp;&amp;($ value1-&gt; name == $ value-&gt; Name))
&lt  ; th&gt;&lt; a href =“{{route('user.show',['id'=&gt; $ value-&gt; pi_id])}}”&gt;&lt; span style =“color:red;”  &gt; {{$ value-&gt; Name}}&lt; / span&gt;&lt; / a&gt;&lt; / th&gt; 
 @endforeach 
 @else 
&lt; th&gt;&lt; a href =“{{route(  'user.show',['id'=&gt; $ value-&gt; pi_id])}}“&gt; {{$ value-&gt;名称}}&lt; / a&gt;&lt; / th&gt; 
 @endif  
&lt; / tr&gt;  
 @endforeach 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • donglao9606 2017-12-01 06:13
    已采纳

    You can change to

    @foreach($data as $value) 
      <tr> 
     @if($value->training_Status == 'No')
     <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
     @foreach($data1 as $value1)
      @if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
     <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
         @endif 
      @endforeach
     @else 
    <th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
     @endif 
     </tr> 
     @endforeach
    
    已采纳该答案
    打赏 评论
  • dongyukui8330 2017-12-01 06:15
    @foreach($data as $value) 
     <tr> 
     @if($value->training_Status == 'No')
       <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
       @foreach($data1 as $value1)
         @if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
         <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
         @endif 
       @endforeach
     @else 
       <th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
     @endif 
     </tr> 
     @endforeach
    

    Should do the job for you

    打赏 评论
  • dongliang2005 2017-12-01 06:23

    @Dkna Just change your code to like this:

    @foreach($data as $value) 
        <tr> 
        @if($value->training_Status == 'No')
           <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
           @foreach($data1 as $value1)
               @if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
                  <th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
               @endif 
           @endforeach
        @else 
            <th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
        @endif 
        </tr> 
    @endforeach
    

    Hope this helps you and fixed your issue!

    打赏 评论

相关推荐 更多相似问题