'Updated Segment Constant', 'message' => 'You have successfully updated the Segment Constant' ]; } /** @var CanUpdateConstant */ private $canUpdateConstant; /** @var UpdatesConstant */ private $updatesConstant; /** @var FetchesSegment */ private $fetchesSegment; /** @var FetchesConstant */ private $fetchesConstant; /** @var UpdatesConstantValueByState */ private $updatesConstantValueByState; /** * UpdateConstantLogic constructor. * @param CanUpdateConstant $canUpdateConstant * @param UpdatesConstant $updatesConstant * @param FetchesSegment $fetchesSegment * @param FetchesConstant $fetchesConstant * @param UpdatesConstantValueByState $updatesConstantValueByState */ public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant,UpdatesConstantValueByState $updatesConstantValueByState) { $this->canUpdateConstant = $canUpdateConstant; $this->updatesConstant = $updatesConstant; $this->fetchesSegment = $fetchesSegment; $this->fetchesConstant = $fetchesConstant; $this->updatesConstantValueByState = $updatesConstantValueByState; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => SegmentConstants::STATE_RATE]); $constantValue = $this->updatesConstantValueByState->execute($constant->value, $request->input('status_id'), $request->input('rate')); $object = new ConstantObject(SegmentConstants::STATE_RATE, (array) $constantValue); $this->canUpdateConstant->passes($object); $constant = $this->updatesConstant->execute($constant, $object); return $this->resourceResponse(new ConstantResource($constant)); } }