id; $this->validatePlanRow($plan_data); $plan = Plan::updateOrCreate([ 'service_code' => $plan_data['service_code'], 'corporate_id' => $corporate->id, 'code' => $plan_data['code'], ], $plan_data); return $plan; } catch (\Exception $e) { throw $e; } } protected function validateBenefitRow($row) { if (empty($row['service_code'])) { throw new ImportRowException(__('benefit.SERVICE_CODE_REQUIRED'), 0, null, $row); } if (empty($row['plan_code'])) { throw new ImportRowException(__('benefit.PLAN_CODE_REQUIRED'), 0, null, $row); } if (empty($row['benefit_code'])) { throw new ImportRowException(__('benefit.BENEFIT_CODE_REQUIRED'), 0, null, $row); } if (empty($row['code'])) { throw new ImportRowException(__('benefit.CUSTOMER_BENEFIT_CODE_REQUIRED'), 0, null, $row); } if (empty($row['description'])) { throw new ImportRowException(__('benefit.DESCRIPTION_REQUIRED'), 0, null, $row); } if (empty($row['limit_amount'])) { throw new ImportRowException(__('benefit.LIMIT_AMOUNT_REQUIRED'), 0, null, $row); } if (empty($row['msc'])) { throw new ImportRowException(__('benefit.MSC_REQUIRED'), 0, null, $row); } if (empty($row['genders'])) { throw new ImportRowException(__('benefit.GENDER_REQUIRED'), 0, null, $row); } } public function handleBenefitRow(Corporate $corporate, $row) { try { $benefit_data = $row; $benefit_data["corporate_id"] = $corporate->id; $this->validateBenefitRow($benefit_data); $plan = Benefit::updateOrCreate([ 'service_code' => $benefit_data['service_code'], 'plan_code' => $benefit_data['plan_code'], 'corporate_id' => $corporate->id, 'code' => $benefit_data['code'], ], $benefit_data); return $plan; } catch (\Exception $e) { throw $e; } } }