repository = $province; parent::__construct(); } /** * Display a list of province. * * @return Response */ public function index(ProvinceRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('k_b::province.names').' :: '); return $this->theme->of('k_b::admin.province.index')->render(); } /** * Display a list of province. * * @return Response */ public function getJson(ProvinceRequest $request) { $pageLimit = $request->input('pageLimit'); $provinces = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Kependudukan\\KB\\Repositories\\Presenter\\ProvinceListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $provinces['recordsTotal'] = $provinces['meta']['pagination']['total']; $provinces['recordsFiltered'] = $provinces['meta']['pagination']['total']; $provinces['request'] = $request->all(); return response()->json($provinces, 200); } /** * Display province. * * @param Request $request * @param Model $province * * @return Response */ public function show(ProvinceRequest $request, Province $province) { if (!$province->exists) { return response()->view('k_b::admin.province.new', compact('province')); } Form::populate($province); return response()->view('k_b::admin.province.show', compact('province')); } /** * Show the form for creating a new province. * * @param Request $request * * @return Response */ public function create(ProvinceRequest $request) { $province = $this->repository->newInstance([]); Form::populate($province); return response()->view('k_b::admin.province.create', compact('province')); } /** * Create new province. * * @param Request $request * * @return Response */ public function store(ProvinceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $province = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('k_b::province.name')]), 'code' => 204, 'redirect' => trans_url('/admin/k_b/province/'.$province->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show province for editing. * * @param Request $request * @param Model $province * * @return Response */ public function edit(ProvinceRequest $request, Province $province) { Form::populate($province); return response()->view('k_b::admin.province.edit', compact('province')); } /** * Update the province. * * @param Request $request * @param Model $province * * @return Response */ public function update(ProvinceRequest $request, Province $province) { try { $attributes = $request->all(); $province->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('k_b::province.name')]), 'code' => 204, 'redirect' => trans_url('/admin/k_b/province/'.$province->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/k_b/province/'.$province->getRouteKey()), ], 400); } } /** * Remove the province. * * @param Model $province * * @return Response */ public function destroy(ProvinceRequest $request, Province $province) { try { $t = $province->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('k_b::province.name')]), 'code' => 202, 'redirect' => trans_url('/admin/k_b/province/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/k_b/province/'.$province->getRouteKey()), ], 400); } } }