repository = $catalogo; parent::__construct(); } /** * Display a list of catalogo. * * @return Response */ public function index(CatalogoAdminWebRequest $request) { if ($request->wantsJson()) { $catalogos = $this->repository->setPresenter('\\Renysh\\Turismo\\Repositories\\Presenter\\CatalogoListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($catalogos, 200); } $this ->theme->prependTitle(trans('turismo::catalogo.names').' :: '); return $this->theme->of('turismo::admin.catalogo.index')->render(); } /** * Display catalogo. * * @param Request $request * @param Model $catalogo * * @return Response */ public function show(CatalogoAdminWebRequest $request, Catalogo $catalogo) { if (!$catalogo->exists) { return response()->view('turismo::admin.catalogo.new', compact('catalogo')); } Form::populate($catalogo); return response()->view('turismo::admin.catalogo.show', compact('catalogo')); } /** * Show the form for creating a new catalogo. * * @param Request $request * * @return Response */ public function create(CatalogoAdminWebRequest $request) { $catalogo = $this->repository->newInstance([]); Form::populate($catalogo); return response()->view('turismo::admin.catalogo.create', compact('catalogo')); } /** * Create new catalogo. * * @param Request $request * * @return Response */ public function store(CatalogoAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $catalogo = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('turismo::catalogo.name')]), 'code' => 204, 'redirect' => trans_url('/admin/turismo/catalogo/'.$catalogo->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show catalogo for editing. * * @param Request $request * @param Model $catalogo * * @return Response */ public function edit(CatalogoAdminWebRequest $request, Catalogo $catalogo) { Form::populate($catalogo); return response()->view('turismo::admin.catalogo.edit', compact('catalogo')); } /** * Update the catalogo. * * @param Request $request * @param Model $catalogo * * @return Response */ public function update(CatalogoAdminWebRequest $request, Catalogo $catalogo) { try { $attributes = $request->all(); $catalogo->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('turismo::catalogo.name')]), 'code' => 204, 'redirect' => trans_url('/admin/turismo/catalogo/'.$catalogo->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/turismo/catalogo/'.$catalogo->getRouteKey()), ], 400); } } /** * Remove the catalogo. * * @param Model $catalogo * * @return Response */ public function destroy(CatalogoAdminWebRequest $request, Catalogo $catalogo) { try { $t = $catalogo->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('turismo::catalogo.name')]), 'code' => 202, 'redirect' => trans_url('/admin/turismo/catalogo/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/turismo/catalogo/'.$catalogo->getRouteKey()), ], 400); } } }