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