无法为if语句仅选择一个条件

时间:2019-04-06 05:45:49

标签: php laravel laravel-5 eloquent

如果第一个问题被证明是正确的,则尝试仅使一个条件成立。 if条件在foreach循环之后。因此,该循环将检查每个循环是否符合条件并给出相应的答案。

我尝试使用@isset和@switch纠正信息。

  <!-- Like a quote -->
<div>
    <div>
        <ul>
            @auth                           
                @if($quote->userLike->count() > 0)                                
                    @foreach($quote->userLike as $like)
                        @if($like->pivot->user_id == $id)
                        <li class="list-inline-item">
                            <form  method="POST" action="{{route('likequote')}" class="likequote">
                            @csrf
                            <button class="btn btn-danger shadow-lg" id="savelike"><i class="fas fa-heart"></i>                             
                        </li>   
                        @endif  
                @endforeach  
                @else
                    <li class="list-inline-item">
                        <form  method="POST" action="{{route('likequote')}}" class="likequote">
                        @csrf
                            <input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
                            <button type="submit" class="btn btn-primary shadow-lg   " id="savelike"><i class="fas fa-heart"></button></i>
                        </form>                                 
                    </li>
                @endif
             @endauth
                <!-- Audio -->
                <li class="list-inline-item">
                    <source src="{{$quote->mp3_url}}" type="audio/mpeg">
                    Your browser does not support the audio tag.
                    </audio>
                </li>                                   
        </ul>
    </div>
</div>
@else

0 个答案:

没有答案