82 lines
2.8 KiB
PHP
82 lines
2.8 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\UpsertSaluranMengundiRequest;
|
|
use App\Models\PusatMengundi;
|
|
use App\Models\SaluranMengundi;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class SaluranMengundiController extends Controller
|
|
{
|
|
use SortsQuery;
|
|
|
|
public function index(PusatMengundi $pusatMengundi): View
|
|
{
|
|
return view('admin.setup.saluran.index', [
|
|
'pusat' => $pusatMengundi,
|
|
'salurans' => $this->sortedQuery(
|
|
SaluranMengundi::query()->where('pusat_mengundi_id', $pusatMengundi->id),
|
|
['number', 'voter_count'],
|
|
'number'
|
|
)->paginate(20)->withQueryString(),
|
|
]);
|
|
}
|
|
|
|
public function create(PusatMengundi $pusatMengundi): View
|
|
{
|
|
return view('admin.setup.saluran.create', [
|
|
'pusat' => $pusatMengundi,
|
|
'saluran' => new SaluranMengundi,
|
|
]);
|
|
}
|
|
|
|
public function store(UpsertSaluranMengundiRequest $request, PusatMengundi $pusatMengundi): RedirectResponse
|
|
{
|
|
$pusatMengundi->saluranMengundis()->create([
|
|
'election_id' => $pusatMengundi->election_id,
|
|
'number' => $request->validated('number'),
|
|
'voter_count' => $request->validated('voter_count'),
|
|
]);
|
|
|
|
return redirect()->route('admin.setup.pusat.saluran.index', $pusatMengundi)
|
|
->with('status', 'Saluran Mengundi telah disimpan.');
|
|
}
|
|
|
|
public function edit(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): View
|
|
{
|
|
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
|
|
|
return view('admin.setup.saluran.edit', [
|
|
'pusat' => $pusatMengundi,
|
|
'saluran' => $saluranMengundi,
|
|
]);
|
|
}
|
|
|
|
public function update(UpsertSaluranMengundiRequest $request, PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): RedirectResponse
|
|
{
|
|
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
|
|
|
$saluranMengundi->update([
|
|
'number' => $request->validated('number'),
|
|
'voter_count' => $request->validated('voter_count'),
|
|
]);
|
|
|
|
return redirect()->route('admin.setup.pusat.saluran.index', $pusatMengundi)
|
|
->with('status', 'Saluran Mengundi telah dikemas kini.');
|
|
}
|
|
|
|
public function destroy(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): RedirectResponse
|
|
{
|
|
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
|
|
|
$saluranMengundi->forceDelete();
|
|
|
|
return redirect()->route('admin.setup.pusat.saluran.index', $pusatMengundi)
|
|
->with('status', 'Saluran Mengundi telah dipadam.');
|
|
}
|
|
}
|