first
This commit is contained in:
100
app/Http/Controllers/Admin/Setup/PositionQuotaController.php
Normal file
100
app/Http/Controllers/Admin/Setup/PositionQuotaController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Setup;
|
||||
|
||||
use App\Http\Concerns\SortsQuery;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\Setup\UpsertPositionQuotaRequest;
|
||||
use App\Models\Position;
|
||||
use App\Models\PositionQuota;
|
||||
use App\Models\PusatMengundi;
|
||||
use App\Models\SaluranMengundi;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PositionQuotaController extends Controller
|
||||
{
|
||||
use SortsQuery;
|
||||
|
||||
public function index(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): View
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
|
||||
return view('admin.setup.quotas.index', [
|
||||
'pusat' => $pusatMengundi,
|
||||
'saluran' => $saluranMengundi,
|
||||
'quotas' => $this->sortedQuery(
|
||||
PositionQuota::query()
|
||||
->with(['position'])
|
||||
->where('saluran_mengundi_id', $saluranMengundi->id),
|
||||
['quota'],
|
||||
'id'
|
||||
)->paginate(25)->withQueryString(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): View
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
|
||||
return view('admin.setup.quotas.create', [
|
||||
'pusat' => $pusatMengundi,
|
||||
'saluran' => $saluranMengundi,
|
||||
'quota' => new PositionQuota,
|
||||
'positions' => Position::query()->orderBy('sort_order')->orderBy('code')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(UpsertPositionQuotaRequest $request, PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi): RedirectResponse
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
|
||||
PositionQuota::query()->updateOrCreate(
|
||||
[
|
||||
'election_id' => $saluranMengundi->election_id,
|
||||
'pusat_mengundi_id' => $pusatMengundi->id,
|
||||
'saluran_mengundi_id' => $saluranMengundi->id,
|
||||
'position_id' => $request->validated('position_id'),
|
||||
],
|
||||
['quota' => $request->validated('quota')],
|
||||
);
|
||||
|
||||
return redirect()->route('admin.setup.pusat.saluran.kuota.index', [$pusatMengundi, $saluranMengundi])
|
||||
->with('status', 'Kekosongan jawatan telah disimpan.');
|
||||
}
|
||||
|
||||
public function edit(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi, PositionQuota $quota): View
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
abort_unless($quota->saluran_mengundi_id === $saluranMengundi->id, 404);
|
||||
|
||||
return view('admin.setup.quotas.edit', [
|
||||
'pusat' => $pusatMengundi,
|
||||
'saluran' => $saluranMengundi,
|
||||
'quota' => $quota->load('position'),
|
||||
'positions' => Position::query()->orderBy('sort_order')->orderBy('code')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpsertPositionQuotaRequest $request, PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi, PositionQuota $quota): RedirectResponse
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
abort_unless($quota->saluran_mengundi_id === $saluranMengundi->id, 404);
|
||||
|
||||
$quota->update(['quota' => $request->validated('quota')]);
|
||||
|
||||
return redirect()->route('admin.setup.pusat.saluran.kuota.index', [$pusatMengundi, $saluranMengundi])
|
||||
->with('status', 'Kekosongan jawatan telah dikemas kini.');
|
||||
}
|
||||
|
||||
public function destroy(PusatMengundi $pusatMengundi, SaluranMengundi $saluranMengundi, PositionQuota $quota): RedirectResponse
|
||||
{
|
||||
abort_unless($saluranMengundi->pusat_mengundi_id === $pusatMengundi->id, 404);
|
||||
abort_unless($quota->saluran_mengundi_id === $saluranMengundi->id, 404);
|
||||
|
||||
$quota->forceDelete();
|
||||
|
||||
return redirect()->route('admin.setup.pusat.saluran.kuota.index', [$pusatMengundi, $saluranMengundi])
|
||||
->with('status', 'Kekosongan jawatan telah dipadam.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user