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