districtRepository = $districtRepository; $this->adminService = $adminService; } /** * Display a listing of the resource. */ public function index() { $data['title'] = 'District List'; $data['districtLists'] = $this->districtRepository->findAll(); return view('admin::districts.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create District'; $data['editable'] = false; $data['provinceLists'] = $this->adminService->pluckProvinces(); return view('admin::districts.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { try { $this->districtRepository->create($request->all()); toastr()->success('District created successfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('district.index'); } /** * Show the specified resource. */ public function show($id) { return view('admin::districts.show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit District'; $data['editable'] = true; $data['district'] = $this->districtRepository->getDistrictById($id); $data['provinceLists'] = $this->adminService->pluckProvinces(); return view('admin::districts.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { try { $this->districtRepository->update($id, $request->all()); toastr()->success('District updated successfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('district.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $this->districtRepository->delete($id); toastr()->success('District deleted successfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('district.index'); } }