repository = $news; } /** * Display a list of news. * * @return Response */ public function index(NewsAdminRequest $request) { $news = $this->repository->setPresenter('\\News\\News\\Repositories\\Presenter\\NewsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('news::news.names').' :: '); $view = $this->theme->of('news::admin.news.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('news::news.name')]); $this->responseData = $news['data']; $this->responseMeta = $news['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display news. * * @param Request $request * @param int $id * * @return Response */ public function show(NewsAdminRequest $request, News $news) { if (!$news->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('news::news.name')]); $this->responseView = view('news::admin.news.new'); return $this -> respond($request); } Form::populate($news); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('news::news.name')]); $this->responseData = $news; $this->responseView = view('news::admin.news.show', compact('news')); return $this -> respond($request); } /** * Show the form for creating a new news. * * @param Request $request * * @return Response */ public function create(NewsAdminRequest $request) { $news = $this->repository->newInstance([]); Form::populate($news); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('news::news.name')]); $this->responseData = $news; $this->responseView = view('news::admin.news.create', compact('news')); return $this -> respond($request); } /** * Create new news. * * @param Request $request * * @return Response */ public function store(NewsAdminRequest $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('news::news.name')]); $this->responseData = $news; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/news/news/'.$news->getRouteKey()); $this->responseView = view('news::admin.news.create', compact('news')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show news for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(NewsAdminRequest $request, News $news) { Form::populate($news); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('news::news.name')]); $this->responseData = $news; $this->responseView = view('news::admin.news.edit', compact('news')); return $this -> respond($request); } /** * Update the news. * * @param Request $request * @param int $id * * @return Response */ public function update(NewsAdminRequest $request, News $news) { try { $attributes = $request->all(); $news->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('news::news.name')]); $this->responseData = $news; $this->responseRedirect = trans_url('/admin/news/news/'.$news->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/news/news/'.$news->getRouteKey()); return $this -> respond($request); } } /** * Remove the news. * * @param int $id * * @return Response */ public function destroy(NewsAdminRequest $request, News $news) { try { $t = $news->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('news::news.name')]); $this->responseRedirect = trans_url('/admin/news/news/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/news/news/'.$news->getRouteKey()); return $this -> respond($request); } } }