'Created Remark', 'message' => 'You have successfully created a new Remark' ]; } /** @var CreateRemarkProcessor */ private $createRemarkProcessor; /** * CreateRemarkLogic constructor. * @param CreateRemarkProcessor $createRemarkProcessor */ public function __construct(CreateRemarkProcessor $createRemarkProcessor) { $this->createRemarkProcessor = $createRemarkProcessor; } /** * @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 { $classs = '\\App\\Models\\' . Str::studly($request->input('model_type')); if (!class_exists($classs)) { throw new MalformedRequestException('Unable to process this entity'); } $remarkOwner = $classs::find($request->route('id')); $remarkObject = new RemarkObject($request->input('content'), auth()->user()->id); $remmark = $this->createRemarkProcessor->execute($remarkOwner, $remarkObject); return $this->resourceResponse(new RemarkResource($remmark)); } }