'Created Segment Constant', 'message' => 'You have successfully created a new Segment Constant' ]; } /** @var CanCreateConstant */ private $canCreateConstant; /** @var CreatesConstant */ private $createsConstant; /** @var FetchesSegment */ private $fetchesSegment; /** * CreateSegmentLogic constructor. * @param CanCreateConstant $canCreateConstant * @param CreatesConstant $createsConstant */ public function __construct(CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant, FetchesSegment $fetchesSegment) { $this->canCreateConstant = $canCreateConstant; $this->createsConstant = $createsConstant; $this->fetchesSegment = $fetchesSegment; } /** * @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 { $constant_object = new ConstantObject($request->input('name'), $request->input('reference'), $request->input('detail')); $segment = $this->fetchesSegment->execute(['id' => $request->input('segment_id')]); $this->canCreateConstant->passes($constant_object); $constant = $this->createsConstant->execute($segment, $constant_object); return $this->resourceResponse(new ConstantResource($constant)); } }