'Updated Comment', 'message' => 'You have successfully updated the Comment' ]; } /** @var CanUpdateComment */ private $canUpdateComment; /** @var UpdatesComment */ private $updatesComment; /** @var FetchesComment */ private $fetchesComment; /** * UpdateCommentControllerLogic constructor. * @param CanUpdateComment $canUpdateComment * @param UpdatesComment $updatesComment * @param FetchesComment $fetchesComment */ public function __construct(CanUpdateComment $canUpdateComment, UpdatesComment $updatesComment, FetchesComment $fetchesComment) { $this->canUpdateComment = $canUpdateComment; $this->updatesComment = $updatesComment; $this->fetchesComment = $fetchesComment; } /** * @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->canUpdateComment->passes($object); $query = $this->fetchesComment->execute(['id' => $request->route('id')]); $query = $this->updatesComment->execute($query, $object); return $this->resourceResponse(new CommentResource($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }