repository = $comments; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Ss\Ss\Repositories\Criteria\CommentsUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(CommentsRequest $request) { $comments = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('ss::comments.names')); return $this->theme->of('ss::user.comments.index', compact('comments'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Comments $comments * * @return Response */ public function show(CommentsRequest $request, Comments $comments) { Form::populate($comments); return $this->theme->of('ss::user.comments.show', compact('comments'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(CommentsRequest $request) { $comments = $this->repository->newInstance([]); Form::populate($comments); $this->theme->prependTitle(trans('ss::comments.names')); return $this->theme->of('ss::user.comments.create', compact('comments'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(CommentsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $comments = $this->repository->create($attributes); return redirect(trans_url('/user/ss/comments')) -> with('message', trans('messages.success.created', ['Module' => trans('ss::comments.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Comments $comments * * @return Response */ public function edit(CommentsRequest $request, Comments $comments) { Form::populate($comments); $this->theme->prependTitle(trans('ss::comments.names')); return $this->theme->of('ss::user.comments.edit', compact('comments'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Comments $comments * * @return Response */ public function update(CommentsRequest $request, Comments $comments) { try { $this->repository->update($request->all(), $comments->getRouteKey()); return redirect(trans_url('/user/ss/comments')) ->with('message', trans('messages.success.updated', ['Module' => trans('ss::comments.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(CommentsRequest $request, Comments $comments) { try { $this->repository->delete($comments->getRouteKey()); return redirect(trans_url('/user/ss/comments')) ->with('message', trans('messages.success.deleted', ['Module' => trans('ss::comments.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }