request = $request; } public function excetute() : 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' => $this->request->participationFeeFirst['amount']->getAmount() ]))->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' => $this->request->participationFeeSecond['amount']->getAmount() ]))->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' => $this->request->participationFeeThird['amount']->getAmount() ]))->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' => $this->request->participationFeeFourth['amount']->getAmount() ]))->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(); } }