repository = $city; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Classifieds\Location\Repositories\Criteria\CityResourceCriteria::class); } /** * Display a list of city. * * @return Response */ public function index(CityRequest $request) { return $this->repository ->setPresenter(\Classifieds\Location\Repositories\Presenter\CityPresenter::class) ->paginate(); } /** * Display city. * * @param Request $request * @param Model $city * * @return Response */ public function show(CityRequest $request, City $city) { return $city->setPresenter(\Classifieds\Location\Repositories\Presenter\CityListPresenter::class); ; } /** * Create new city. * * @param Request $request * * @return Response */ public function store(CityRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('location::city.name')]); $code = 204; $status = 'success'; $url = guard_url('location/city/' . $city->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/city'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the city. * * @param Request $request * @param Model $city * * @return Response */ public function update(CityRequest $request, City $city) { try { $data = $request->all(); $city->update($data); $message = trans('messages.success.updated', ['Module' => trans('location::city.name')]); $code = 204; $status = 'success'; $url = guard_url('location/city/' . $city->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/city/' . $city->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the city. * * @param Model $city * * @return Response */ public function destroy(CityRequest $request, City $city) { try { $city->delete(); $message = trans('messages.success.deleted', ['Module' => trans('location::city.name')]); $code = 202; $status = 'success'; $url = guard_url('location/city/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/city/' . $city->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }