@php $employee = $employee ?? ($formEmployee ?? null); $isEdit = filled($employee); $formAction = $isEdit ? route('masters.employees.update', $employee) : route('masters.employees.store'); $opts = $formOptions ?? \App\Support\EmployeeFormOptions::class; $val = fn (string $field, $default = '') => old($field, $employee?->{$field} ?? $default); $dateVal = fn (string $field) => old($field, $employee && $employee->{$field} ? $employee->{$field}->format('Y-m-d') : ''); $lineRows = function (string $type, int $count) use ($employee) { $existing = $employee ? $employee->salaryLines->where('line_type', $type)->values() : collect(); $rows = []; for ($i = 0; $i < $count; $i++) { $rows[] = $existing[$i] ?? null; } return $rows; }; $earningRows = $lineRows('earning', 10); $deductionRows = $lineRows('deduction', 10); $irregularRows = $lineRows('irregular', 4); @endphp