'Updated Segment', 'message' => 'You have successfully updated the Segment' ]; } /** @var CanUpdateSegment */ private $canUpdateSegment; /** @var UpdatesSegment */ private $updatesSegment; /** @var FetchesSegment */ private $fetchesSegment; /** * UpdateSegmentLogic constructor. * @param CanUpdateSegment $canUpdateSegment * @param UpdatesSegment $updatesSegment * @param FetchesSegment $fetchesSegment */ public function __construct( CanUpdateSegment $canUpdateSegment, UpdatesSegment $updatesSegment, FetchesSegment $fetchesSegment ) { $this->canUpdateSegment = $canUpdateSegment; $this->updatesSegment = $updatesSegment; $this->fetchesSegment = $fetchesSegment; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { DB::beginTransaction(); $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); $segment_object = new SegmentObject( $request->input('name', $segment_query->name) ); $this->canUpdateSegment->passes($segment_object); $segment_query = $this->updatesSegment->execute($segment_query, $segment_object); DB::commit(); return $this->resourceResponse(new SegmentResource($segment_query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }