71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Setup;
|
|
|
|
use App\Http\Concerns\SortsQuery;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Setup\UpsertDaerahMengundiRequest;
|
|
use App\Models\BahagianPilihanraya;
|
|
use App\Models\DaerahMengundi;
|
|
use App\Models\Election;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class DaerahMengundiController extends Controller
|
|
{
|
|
use SortsQuery;
|
|
|
|
public function index(): View
|
|
{
|
|
return view('admin.setup.daerah.index', [
|
|
'daerahs' => $this->sortedQuery(
|
|
DaerahMengundi::query()->with(['election', 'bahagianPilihanraya']),
|
|
['code', 'name'],
|
|
'code'
|
|
)->paginate(15)->withQueryString(),
|
|
]);
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
return view('admin.setup.daerah.create', [
|
|
'daerah' => new DaerahMengundi,
|
|
'elections' => Election::query()->orderBy('name')->get(),
|
|
'bahagians' => BahagianPilihanraya::query()->orderBy('name')->get(),
|
|
]);
|
|
}
|
|
|
|
public function store(UpsertDaerahMengundiRequest $request): RedirectResponse
|
|
{
|
|
DaerahMengundi::query()->create($request->validated());
|
|
|
|
return redirect()->route('admin.setup.daerah.index')
|
|
->with('status', 'Daerah Mengundi telah disimpan.');
|
|
}
|
|
|
|
public function edit(DaerahMengundi $daerahMengundi): View
|
|
{
|
|
return view('admin.setup.daerah.edit', [
|
|
'daerah' => $daerahMengundi,
|
|
'elections' => Election::query()->orderBy('name')->get(),
|
|
'bahagians' => BahagianPilihanraya::query()->orderBy('name')->get(),
|
|
]);
|
|
}
|
|
|
|
public function update(UpsertDaerahMengundiRequest $request, DaerahMengundi $daerahMengundi): RedirectResponse
|
|
{
|
|
$daerahMengundi->update($request->validated());
|
|
|
|
return redirect()->route('admin.setup.daerah.index')
|
|
->with('status', 'Daerah Mengundi telah dikemas kini.');
|
|
}
|
|
|
|
public function destroy(DaerahMengundi $daerahMengundi): RedirectResponse
|
|
{
|
|
$daerahMengundi->forceDelete();
|
|
|
|
return redirect()->route('admin.setup.daerah.index')
|
|
->with('status', 'Daerah Mengundi telah dipadam.');
|
|
}
|
|
}
|