repository = $comment; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Service\Repositories\Criteria\CommentResourceCriteria::class); } /** * Display a list of comment. * * @return Response */ public function index(CommentRequest $request) { return $this->repository ->setPresenter(\B2buy\Service\Repositories\Presenter\CommentPresenter::class) ->paginate(); } /** * Display comment. * * @param Request $request * @param Model $comment * * @return Response */ public function show(CommentRequest $request, Comment $comment) { return $comment->setPresenter(\B2buy\Service\Repositories\Presenter\CommentListPresenter::class); ; } /** * Create new comment. * * @param Request $request * * @return Response */ public function store(CommentRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('service::comment.name')]); $code = 204; $status = 'success'; $url = guard_url('service/comment/' . $comment->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/comment'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the comment. * * @param Request $request * @param Model $comment * * @return Response */ public function update(CommentRequest $request, Comment $comment) { try { $data = $request->all(); $comment->update($data); $message = trans('messages.success.updated', ['Module' => trans('service::comment.name')]); $code = 204; $status = 'success'; $url = guard_url('service/comment/' . $comment->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/comment/' . $comment->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the comment. * * @param Model $comment * * @return Response */ public function destroy(CommentRequest $request, Comment $comment) { try { $comment->delete(); $message = trans('messages.success.deleted', ['Module' => trans('service::comment.name')]); $code = 202; $status = 'success'; $url = guard_url('service/comment/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/comment/' . $comment->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }