repository = $province; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Kependudukan\KB\Repositories\Criteria\ProvinceUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(ProvinceRequest $request) { $provinces = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('k_b::province.names')); return $this->theme->of('k_b::user.province.index', compact('provinces'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Province $province * * @return Response */ public function show(ProvinceRequest $request, Province $province) { Form::populate($province); return $this->theme->of('k_b::user.province.show', compact('province'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(ProvinceRequest $request) { $province = $this->repository->newInstance([]); Form::populate($province); $this->theme->prependTitle(trans('k_b::province.names')); return $this->theme->of('k_b::user.province.create', compact('province'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(ProvinceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $province = $this->repository->create($attributes); return redirect(trans_url('/user/k_b/province')) -> with('message', trans('messages.success.created', ['Module' => trans('k_b::province.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Province $province * * @return Response */ public function edit(ProvinceRequest $request, Province $province) { Form::populate($province); $this->theme->prependTitle(trans('k_b::province.names')); return $this->theme->of('k_b::user.province.edit', compact('province'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Province $province * * @return Response */ public function update(ProvinceRequest $request, Province $province) { try { $this->repository->update($request->all(), $province->getRouteKey()); return redirect(trans_url('/user/k_b/province')) ->with('message', trans('messages.success.updated', ['Module' => trans('k_b::province.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(ProvinceRequest $request, Province $province) { try { $this->repository->delete($province->getRouteKey()); return redirect(trans_url('/user/k_b/province')) ->with('message', trans('messages.success.deleted', ['Module' => trans('k_b::province.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }