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