'Created Contact', 'message' => 'You have successfully created a new Contact' ]; } /** @var CanCreateContact */ private $canCreateContact; /** @var CreatesContact */ private $createsContact; /** * CreateContactControllerLogic constructor. * @param CanCreateContact $canCreateContact * @param CreatesContact $createsContact */ public function __construct(CanCreateContact $canCreateContact, CreatesContact $createsContact) { $this->canCreateContact = $canCreateContact; $this->createsContact = $createsContact; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { dd($request->all()); try { $object = new ContactObject($request->input('company_id'), $request->input('name'), $request->input('designation'), $request->input('email'), $request->input('phone'), $request->input('wechat_id')); $this->canCreateContact->passes($object); $query = $this->createsContact->execute($object); return $this->resourceResponse(new ContactResource($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }