如果条件为true,则显示阻止按钮,否则,条件为false,显示取消阻止按钮:Laravel,Javascript

时间:2019-05-23 16:16:49

标签: javascript php laravel eloquent laravel-5.8

如果$block->user_username数据为空,则显示block按钮,否则运行另一个if and else条件。但是在foreach循环中,其他方法无法正常工作@else <a href="#0" class="cd-popup-trigger">Block2</a>,请任何人帮助我。 任何人都知道执行此操作的任何其他条件。

@else <a href="#0" class="cd-popup-trigger">Block2</a> @endif仅当条件正常时,此条件才卡住。如果此@if(Auth::user()->name == $block->user_username && $user->username == $block->block_username)条件为假,则代码不显示其他条件。

 @foreach($blocked as $block)    
                   @if(empty($block->user_username ))
                     <a href="#0" class="cd-popup-trigger">Block1</a>

                   @else
                        @if(Auth::user()->username == $block->user_username and $user->username == $block->block_username)
                         <a href="#0" class="cd-popup-trigger">Unblock</a>
                         @else
                            <a href="#0" class="cd-popup-trigger">Block2</a>
                        @endif
                    @endif
            @endforeach  

1 个答案:

答案 0 :(得分:1)

尝试此代码

@foreach($blocked as $block)    
  @if(!empty($block->user_username ))
    @if(Auth::user()->name == $block->user_username && $user->username == $block->block_username)
      <a href="#0" class="cd-popup-trigger">Unblock</a>
    @else
      <a href="#0" class="cd-popup-trigger">Block2</a>
    @endif
  @else
     <a href="#0" class="cd-popup-trigger">Block1</a> 
  @endif
@endforeach 

我希望它将对您有帮助