$data */ protected function handleRecordCreation(array $data): Model { $profitCenterIds = (array) $data['profit_center_id']; $lastRecord = null; foreach ($profitCenterIds as $profitCenterId) { $lastRecord = ProfitCenterSupplierSchedule::create([ 'profit_center_id' => $profitCenterId, 'supplier_id' => $data['supplier_id'], 'delivery_schedule_id' => $data['delivery_schedule_id'], ]); } return $lastRecord; } }