function returnSeriesRandom($serie) { $result = DB::select(' SELECT * FROM series WHERE series.id != ? ORDER BY RAND() limit 2', [$serie->id]); if (empty($result)) { return returnSeriesRandom($serie); } if (isEmptySeries($result[0])) { return returnSeriesRandom($serie); } return $result; }
<div class="series"> @foreach($result as $temp) @if ( !isEmptySeries($temp) ) <?php $emptyRecommendations = false; ?> <div class="mix ttr" onclick="window.location.href='/series/{{$temp->title}}';" style="display: block"> <div class="ttd" style="width: 100%;">{{ $temp->title }}</div> </div> @endif @endforeach @if ( $emptyRecommendations ) <?php $recommendations = returnSeriesRandom($serie); ?> @foreach($recommendations as $temp) @if ( !isEmptySeries($temp) ) <div class="mix ttr" onclick="window.location.href='/series/{{$temp->title}}';" style="display: block"> <div class="ttd" style="width: 100%;">{{ $temp->title }}</div> </div> @endif @endforeach @endif </div> </div> <div style="clear: both"></div> @if ( $serie->makerId === Auth::id() ) <hr style="margin-top: 50px;"/>