repository = $comments; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Comment\Repositories\Criteria\CommentsResourceCriteria::class); } /** * Display a list of comments. * * @return Response */ public function index(CommentsRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Comment\Repositories\Presenter\CommentsPresenter::class) ->$function(); } $comments = $this->repository->paginate(); return $this->response->title(trans('comment::comments.names')) ->view('comment::comments.index', true) ->data(compact('comments')) ->output(); } /** * Display comments. * * @param Request $request * @param Model $comments * * @return Response */ public function show(CommentsRequest $request, Comments $comments) { if ($comments->exists) { $view = 'comment::comments.show'; } else { $view = 'comment::comments.new'; } return $this->response->title(trans('app.view') . ' ' . trans('comment::comments.name')) ->data(compact('comments')) ->view($view, true) ->output(); } /** * Show the form for creating a new comments. * * @param Request $request * * @return Response */ public function create(CommentsRequest $request) { $comments = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('comment::comments.name')) ->view('comment::comments.create', true) ->data(compact('comments')) ->output(); } /** * Create new comments. * * @param Request $request * * @return Response */ public function store(CommentsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $comments = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('comment::comments.name')])) ->code(204) ->status('success') ->url(guard_url('comment/comments/' . $comments->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/comment/comments')) ->redirect(); } } /** * Show comments for editing. * * @param Request $request * @param Model $comments * * @return Response */ public function edit(CommentsRequest $request, Comments $comments) { return $this->response->title(trans('app.edit') . ' ' . trans('comment::comments.name')) ->view('comment::comments.edit', true) ->data(compact('comments')) ->output(); } /** * Update the comments. * * @param Request $request * @param Model $comments * * @return Response */ public function update(CommentsRequest $request, Comments $comments) { try { $attributes = $request->all(); $comments->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('comment::comments.name')])) ->code(204) ->status('success') ->url(guard_url('comment/comments/' . $comments->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('comment/comments/' . $comments->getRouteKey())) ->redirect(); } } /** * Remove the comments. * * @param Model $comments * * @return Response */ public function destroy(CommentsRequest $request, Comments $comments) { try { $comments->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('comment::comments.name')])) ->code(202) ->status('success') ->url(guard_url('comment/comments/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('comment/comments/' . $comments->getRouteKey())) ->redirect(); } } /** * Remove multiple comments. * * @param Model $comments * * @return Response */ public function delete(CommentsRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('comment::comments.name')])) ->status("success") ->code(202) ->url(guard_url('comment/comments')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/comment/comments')) ->redirect(); } } /** * Restore deleted comments. * * @param Model $comments * * @return Response */ public function restore(CommentsRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('comment::comments.name')])) ->status("success") ->code(202) ->url(guard_url('/comment/comments')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/comment/comments/')) ->redirect(); } } }