repository = $comment; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Project\Pm\Repositories\Criteria\CommentResourceCriteria::class); } /** * Display a list of comment. * * @return Response */ public function index(CommentRequest $request) { return $this->repository ->setPresenter(\Project\Pm\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(\Project\Pm\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('pm::comment.name')]); $code = 204; $status = 'success'; $url = guard_url('pm/comment/' . $comment->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('pm/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('pm::comment.name')]); $code = 204; $status = 'success'; $url = guard_url('pm/comment/' . $comment->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('pm/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('pm::comment.name')]); $code = 202; $status = 'success'; $url = guard_url('pm/comment/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('pm/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); } }