@php // detect if controller provided a paginator (server-side pagination) $serverPaginated = (isset($songs) && is_object($songs) && method_exists($songs, 'links')) ? true : false; // If the parent view provided a paginator ($songs) rather than a prepared $songsList, // build $songsList here so the component logic can remain unchanged. if((!isset($songsList) || !is_array($songsList) || count($songsList) == 0) && isset($songs) && count($songs) > 0){ $songsList = []; $idx = 1; foreach($songs as $sng){ $artist_id = json_decode($sng->artist_id); $artist_array = []; if(is_array($artist_id)){ foreach($artist_id as $artist){ $art = Modules\Artist\Entities\Artist::select('artist_name')->where('id',$artist)->first(); if($art){ $artist_array[] = $art->artist_name; } } } $artist_name = implode(',',$artist_array); $songsList[] = [ 'songs' => $sng, 'artist_name' => $artist_name, 'id' => $idx ]; $idx++; } } $enableGuest = false; foreach($songsList as $song): if($song['songs']->guest_id != null){ $enableGuest = true; } endforeach @endphp
@if(count($songs) > 0) @php $i = 1; @endphp @foreach($songsList as $song) @php $artist_name = $song['artist_name']; $programPlaylist[] =audioPath($song['songs']); $guestDetails = $song['songs']->guest_id; if($guestDetails!=null){ $guestDetails = json_decode($guestDetails,true); } $guest_name = ""; if(is_array($guestDetails) && count($guestDetails) > 0){ $guest_list = Modules\Artist\Entities\Artist::select('artist_name')->whereIn('id',$guestDetails)->get(); foreach ($guest_list as $key => $value) { $guest_name .= ", ".$value->artist_name; } $guest_name = ltrim($guest_name,","); } @endphp @php // expose raw date and duration data attributes for client-side sort/filter $created_ts = strtotime($song['songs']->created_at); $duration_text = $song['songs']->audio_duration ?? ''; @endphp @php $i++; @endphp @endforeach @if($serverPaginated)
{!! $songs->links() !!}
@else @endif @else
No songs found.
@endif
@if(!$serverPaginated) @endif