{$col}; } // Special fields if ($ret['airline']) { $ret['airline'] = $expense->airline->icao; } if ($ret['flight_type']) { $ret['flight_type'] = $ret['flight_type'][0]; } // For the different expense types, instead of exporting // the ID, export a specific column if ($expense->ref_model === Expense::class) { $ret['ref_model'] = ''; $ret['ref_model_id'] = ''; } else { $obj = $expense->getReferencedObject(); if (!$obj) { // bail out return $ret; } if ($expense->ref_model === Aircraft::class) { $ret['ref_model_id'] = $obj->registration; } elseif ($expense->ref_model === Airport::class) { $ret['ref_model_id'] = $obj->icao; } elseif ($expense->ref_model === Subfleet::class) { $ret['ref_model_id'] = $obj->type; } } // And convert the ref_model into the shorter name $ret['ref_model'] = str_replace('App\Models\\', '', $ret['ref_model']); return array_values($ret); } }