repository = $article; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(ArticleUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Article\Repositories\Criteria\ArticleUserCriteria()); $articles = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('article::article.names').' :: '); return $this->theme->of('article::user.article.index', compact('articles'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Article $article * * @return Response */ public function show(ArticleUserRequest $request, Article $article) { Form::populate($article); return $this->theme->of('article::user.article.show', compact('article'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(ArticleUserRequest $request) { $article = $this->repository->newInstance([]); Form::populate($article); return $this->theme->of('article::user.article.create', compact('article'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(ArticleUserRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $article = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('article::article.name')]); $this->responseRedirect = trans_url('/user/article/article'); return $this -> respond($request); } 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 Article $article * * @return Response */ public function edit(ArticleUserRequest $request, Article $article) { Form::populate($article); return $this->theme->of('article::user.article.edit', compact('article'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Article $article * * @return Response */ public function update(ArticleUserRequest $request, Article $article) { try { $this->repository->update($request->all(), $article->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('article::article.name')]); $this->responseRedirect = trans_url('/user/article/article'); return $this -> respond($request); } 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(ArticleUserRequest $request, Article $article) { try { $this->repository->delete($article->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('article::article.name')]); $this->responseRedirect = trans_url('/user/article/article'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }