repository = $comments; parent::__construct(); } /** * Display a list of comments. * * @return Response */ public function index(CommentsRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('ss::comments.names').' :: '); return $this->theme->of('ss::admin.comments.index')->render(); } /** * Display a list of comments. * * @return Response */ public function getJson(CommentsRequest $request) { $pageLimit = $request->input('pageLimit'); $comments = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Ss\\Ss\\Repositories\\Presenter\\CommentsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $comments['recordsTotal'] = $comments['meta']['pagination']['total']; $comments['recordsFiltered'] = $comments['meta']['pagination']['total']; $comments['request'] = $request->all(); return response()->json($comments, 200); } /** * Display comments. * * @param Request $request * @param Model $comments * * @return Response */ public function show(CommentsRequest $request, Comments $comments) { if (!$comments->exists) { return response()->view('ss::admin.comments.new', compact('comments')); } Form::populate($comments); return response()->view('ss::admin.comments.show', compact('comments')); } /** * Show the form for creating a new comments. * * @param Request $request * * @return Response */ public function create(CommentsRequest $request) { $comments = $this->repository->newInstance([]); Form::populate($comments); return response()->view('ss::admin.comments.create', compact('comments')); } /** * Create new comments. * * @param Request $request * * @return Response */ public function store(CommentsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $comments = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('ss::comments.name')]), 'code' => 204, 'redirect' => trans_url('/admin/ss/comments/'.$comments->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show comments for editing. * * @param Request $request * @param Model $comments * * @return Response */ public function edit(CommentsRequest $request, Comments $comments) { Form::populate($comments); return response()->view('ss::admin.comments.edit', compact('comments')); } /** * 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 response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('ss::comments.name')]), 'code' => 204, 'redirect' => trans_url('/admin/ss/comments/'.$comments->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/ss/comments/'.$comments->getRouteKey()), ], 400); } } /** * Remove the comments. * * @param Model $comments * * @return Response */ public function destroy(CommentsRequest $request, Comments $comments) { try { $t = $comments->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('ss::comments.name')]), 'code' => 202, 'redirect' => trans_url('/admin/ss/comments/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/ss/comments/'.$comments->getRouteKey()), ], 400); } } }