request = $request; } public function execute() : SetParticipationFeesResponse { $response = new SetParticipationFeesResponse(); $this->cleanBefore(); $this->request->event->participationFee1()->associate(EventParticipationFee::create([ 'tenant' => app('tenant')->slug, 'type' => $this->request->participationFeeFirst['type'], 'name' => $this->request->participationFeeFirst['name'], 'description' => $this->request->participationFeeFirst['description'], 'amount_standard' => $this->request->participationFeeFirst['amount_standard']->getAmount(), 'amount_reduced' => null !== $this->request->participationFeeFirst['amount_reduced'] ? $this->request->participationFeeFirst['amount_reduced']->getAmount() : null, 'amount_solidarity' => null !== $this->request->participationFeeFirst['amount_solidarity'] ? $this->request->participationFeeFirst['amount_solidarity']->getAmount() : null, ]))->save(); if ($this->request->participationFeeSecond !== null) { $this->request->event->participationFee2()->associate(EventParticipationFee::create([ 'tenant' => app('tenant')->slug, 'type' => $this->request->participationFeeSecond['type'], 'name' => $this->request->participationFeeSecond['name'], 'description' => $this->request->participationFeeSecond['description'], 'amount_standard' => $this->request->participationFeeSecond['amount_standard']->getAmount(), 'amount_reduced' => null !== $this->request->participationFeeSecond['amount_reduced'] ? $this->request->participationFeeSecond['amount_reduced']->getAmount() : null, 'amount_solidarity' => null !== $this->request->participationFeeSecond['amount_solidarity'] ? $this->request->participationFeeSecond['amount_solidarity']->getAmount() : null, ]))->save(); } if ($this->request->participationFeeThird !== null) { $this->request->event->participationFee3()->associate(EventParticipationFee::create([ 'tenant' => app('tenant')->slug, 'type' => $this->request->participationFeeThird['type'], 'name' => $this->request->participationFeeThird['name'], 'description' => $this->request->participationFeeThird['description'], 'amount_standard' => $this->request->participationFeeThird['amount_standard']->getAmount(), 'amount_reduced' => null !== $this->request->participationFeeThird['amount_reduced'] ? $this->request->participationFeeThird['amount_reduced']->getAmount() : null, 'amount_solidarity' => null !== $this->request->participationFeeThird['amount_solidarity'] ? $this->request->participationFeeThird['amount_solidarity']->getAmount() : null, ]))->save(); } if ($this->request->participationFeeFourth !== null) { $this->request->event->participationFee4()->associate(EventParticipationFee::create([ 'tenant' => app('tenant')->slug, 'type' => $this->request->participationFeeFourth['type'], 'name' => $this->request->participationFeeFourth['name'], 'description' => $this->request->participationFeeFourth['description'], 'amount_standard' => $this->request->participationFeeFourth['amount_standard']->getAmount(), 'amount_reduced' => null !== $this->request->participationFeeFourth['amount_reduced'] ? $this->request->participationFeeFourth['amount_reduced']->getAmount() : null, 'amount_solidarity' => null !== $this->request->participationFeeFourth['amount_solidarity'] ? $this->request->participationFeeFourth['amount_solidarity']->getAmount() : null, ]))->save(); } $this->request->event->save(); $response->success = true; return $response; } private function cleanBefore() { if ($this->request->event->participationFee1()->first() !== null) { $this->request->event->participationFee1()->first()->delete(); } if ($this->request->event->participationFee2()->first() !== null) { $this->request->event->participationFee2()->first()->delete(); } if ($this->request->event->participationFee3()->first() !== null) { $this->request->event->participationFee3()->first()->delete(); } if ($this->request->event->participationFee4()->first() !== null) { $this->request->event->participationFee4()->first()->delete(); } $this->request->event->save(); } }