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