'Created Comment', 'message' => 'You have successfully created a new Comment' ]; } /** @var CanCreateComment */ private $canCreateComment; /** @var CreatesComment */ private $createsComment; /** * CreateCommentControllerLogic constructor. * @param CanCreateComment $canCreateComment * @param CreatesComment $createsComment */ public function __construct(CanCreateComment $canCreateComment, CreatesComment $createsComment) { $this->canCreateComment = $canCreateComment; $this->createsComment = $createsComment; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $object = new CommentObject($request->input('commentable_id'), $request->input('commentable_type'), Auth::user()->getAuthIdentifier(), $request->input('comment')); $this->canCreateComment->passes($object); $query = $this->createsComment->execute($object); return $this->response(); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }