@php // Combine all records into a single collection $allNotes = collect(); $lead->recordings->each(function ($recording) use ($allNotes) { $allNotes->push([ 'type' => 'recording', 'data' => $recording, 'created_at' => $recording->start_datetime, ]); }); $lead->emails->each(function ($email) use ($allNotes) { $allNotes->push([ 'type' => 'email', 'data' => $email, 'created_at' => $email->created_at, ]); }); $lead->leadSMS->each(function ($sms) use ($allNotes) { $allNotes->push([ 'type' => 'sms', 'data' => $sms, 'created_at' => $sms->created_at, ]); }); $lead->leadWhatsappSMS->each(function ($sms) use ($allNotes) { $allNotes->push([ 'type' => 'whatsapp', 'data' => $sms, 'created_at' => $sms->created_at, ]); }); $sortedNotes = $allNotes->sortByDesc('created_at'); @endphp @if ($sortedNotes->count() > 0)
{{ $note['data']->message }}