'Updated Standard Segment Constant', 'message' => 'You have successfully updated the Standard Segment Constant' ]; } /** @var CanUpdateStandardSegmentConstant */ private $canUpdateStandardSegmentConstant; /** @var UpdatesSegmentConstantTax */ private $updatesSegmentConstant; /** @var FetchesSegmentConstant */ private $fetchesSegmentConstant; /** * UpdateStandardSegmentConstantLogic constructor. * @param CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant * @param UpdatesSegmentConstant $updatesSegmentConstant * @param FetchesSegmentConstant $fetchesSegmentConstant */ public function __construct( CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant, UpdatesSegmentConstant $updatesSegmentConstant, FetchesSegmentConstant $fetchesSegmentConstant ) { $this->canUpdateStandardSegmentConstant = $canUpdateStandardSegmentConstant; $this->updatesSegmentConstant = $updatesSegmentConstant; $this->fetchesSegmentConstant = $fetchesSegmentConstant; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { DB::beginTransaction(); $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); $segment_constant_object = new SegmentConstantObject( $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('detail') ); $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->updatesSegmentConstant->execute($segment_constant_query, $segment_constant_object); DB::commit(); return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }