109 lines
2.9 KiB
PHP
109 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Modules\Admin\Repositories\DistrictRepository;
|
|
use Modules\Admin\Services\AdminService;
|
|
|
|
class DistrictController extends Controller
|
|
{
|
|
private $districtRepository;
|
|
private $adminService;
|
|
|
|
public function __construct(DistrictRepository $districtRepository, AdminService $adminService)
|
|
{
|
|
$this->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');
|
|
}
|
|
}
|