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\ProvinceRepository;
|
||
|
use Modules\Admin\Services\AdminService;
|
||
|
|
||
|
class ProvinceController extends Controller
|
||
|
{
|
||
|
private $provinceRepository;
|
||
|
private $adminService;
|
||
|
|
||
|
public function __construct(ProvinceRepository $provinceRepository, AdminService $adminService)
|
||
|
{
|
||
|
$this->provinceRepository = $provinceRepository;
|
||
|
$this->adminService = $adminService;
|
||
|
}
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
$data['title'] = 'Province List';
|
||
|
$data['provinceLists'] = $this->provinceRepository->findAll();
|
||
|
return view('admin::provinces.index', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for creating a new resource.
|
||
|
*/
|
||
|
public function create()
|
||
|
{
|
||
|
$data['title'] = 'Create Province';
|
||
|
$data['editable'] = false;
|
||
|
$data['countryLists'] = $this->adminService->pluckCountries();
|
||
|
return view('admin::provinces.create', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*/
|
||
|
public function store(Request $request): RedirectResponse
|
||
|
{
|
||
|
try {
|
||
|
$this->provinceRepository->create($request->all());
|
||
|
toastr()->success('Province created successfully');
|
||
|
} catch (\Throwable $th) {
|
||
|
toastr()->error($th->getMessage());
|
||
|
|
||
|
}
|
||
|
return redirect()->route('province.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the specified resource.
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
return view('admin::provinces.show');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for editing the specified resource.
|
||
|
*/
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$data['title'] = 'Edit Province';
|
||
|
$data['editable'] = true;
|
||
|
$data['province'] = $this->provinceRepository->getProvinceById($id);
|
||
|
$data['countryLists'] = $this->adminService->pluckCountries();
|
||
|
return view('admin::provinces.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(Request $request, $id): RedirectResponse
|
||
|
{
|
||
|
try {
|
||
|
$this->provinceRepository->update($id, $request->all());
|
||
|
toastr()->success('Province updated successfully');
|
||
|
|
||
|
} catch (\Throwable $th) {
|
||
|
toastr()->error($th->getMessage());
|
||
|
}
|
||
|
return redirect()->route('province.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
try {
|
||
|
|
||
|
$this->provinceRepository->delete($id);
|
||
|
toastr()->success('Province deleted successfully');
|
||
|
|
||
|
} catch (\Throwable $th) {
|
||
|
toastr()->error($th->getMessage());
|
||
|
}
|
||
|
return redirect()->route('province.index');
|
||
|
}
|
||
|
}
|