@foreach ($data as $key => $item) @php $trainingGivenBy = null; if ( !empty($item->training_user_type) && $item->training_user_type == 'employee' ) { $trainingGivenBy = $item->employeeGivenByName ?? null; } else { $trainingGivenBy = $item->userGivenByName ?? null; } @endphp @endforeach