form = CityForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.location.modules'), 'location', guard_url('location')); } /** * Display a list of city. * * @return Response */ public function index(CityResourceRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = City::pushScope(new RequestScope()) ->pushScope(new CityResourceScope()) ->paginate($pageLimit); $data = new CitiesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('location::city.names')) ->view('location::city.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display city. * * @param Request $request * @param Model $city * * @return Response */ public function show(CityResourceRequest $request, City $model) { $form = $this->form; $modules = $this->modules; $data = new CityResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('location::city.name')) ->data(compact('data', 'form', 'modules')) ->view('location::city.show') ->output(); } /** * Show the form for creating a new city. * * @param Request $request * * @return Response */ public function create(CityResourceRequest $request, City $model) { $form = $this->form; $modules = $this->modules; $data = new CityResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('location::city.name')) ->view('location::city.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new city. * * @param Request $request * * @return Response */ public function store(CityResourceRequest $request, City $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new CityResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('location::city.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('location/city/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/location/city')) ->redirect(); } } /** * Show city for editing. * * @param Request $request * @param Model $city * * @return Response */ public function edit(CityResourceRequest $request, City $model) { $form = $this->form; $modules = $this->modules; $data = new CityResource($model); // return view('location::city.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('location::city.name')) ->view('location::city.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the city. * * @param Request $request * @param Model $city * * @return Response */ public function update(CityResourceRequest $request, City $model) { try { $attributes = $request->all(); $model->update($attributes); $data = new CityResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('location::city.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('location/city/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/city/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the city. * * @param Model $city * * @return Response */ public function destroy(CityResourceRequest $request, City $model) { try { $model->delete(); $data = new CityResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('location::city.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('location/city/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/city/' . $model->getRouteKey())) ->redirect(); } } }