'Updated Segment Constant', 'message' => 'You have successfully updated the Segment Constant' ]; } /** @var CanUpdateConstant */ private $canUpdateConstant; /** @var UpdatesConstant */ private $updatesConstant; /** @var FetchesConstant */ private $fetchesConstant; /** * UpdateSegmentLogic constructor. * @param CanUpdateConstant $canUpdateConstant * @param UpdatesConstant $updatesConstant * @param FetchesConstant $fetchesConstant */ public function __construct( CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesConstant $fetchesConstant ) { $this->canUpdateConstant = $canUpdateConstant; $this->updatesConstant = $updatesConstant; $this->fetchesConstant = $fetchesConstant; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { DB::beginTransaction(); $constant_query = $this->fetchesConstant->execute(['id' => $request->route('id')]); $constant_object = new ConstantObject( $request->input('name', $constant_query->name), $request->input('reference', $constant_query->reference), $request->input('detail', (array) $constant_query->detail)); $this->canUpdateConstant->passes($constant_object); $constant_query = $this->updatesConstant->execute($constant_query, $constant_object); DB::commit(); return $this->resourceResponse(new ConstantResource($constant_query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }