Could you do a count on both $requests and $sentUsers, putting that in an if statement before the loops?
Apr 15, 2015
4
Level 1
Check if forelse is empty
Hi there,
I have two for loops. One is a forelse and one is a foreach. I'm aware this may need to change.
I'm trying to combine them so that I can output data from each loop. The problem I'm having is that if the first loop is empty, it outputs that it's empty. The second loop doesn't output anything if it's empty. What I'm trying to do is so that if both loops are empty, then output the empty message. Anyone have an idea how I can do this?
@forelse($requests as $request)
<h4 class="profile-name">{{ $opponent->username }} said hi also</h4>
@if ($opponent->ratingActive == 1)
<h6 class="profile-rank"><span class="icon-rank"></span> {{ $opponent->rating }}</h6>
@endif
@empty
//OUTPUT THIS IF BOTH LOOPS RETURN EMPTY-----------------------------
<div class="game-request nn-container">
<h4 class="no-margin nn-text">No notifications</h4>
</div>
@endforelse
@forelse($sentUsers as $sentUser)
@if(isset($venueExists) && $venueExists->venue)
@foreach($receivedUsers as $receivedUser)
<h4 class="profile-name">{{ $receivedUser->username }} said hi</h4>
@endforeach
<h5><span class="green-highlight bold">{{ $venueExists->venue }}</span></h5>
@endif
@empty
@endforelse
Please or to participate in this conversation.