@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\ConsultationStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UpdateConsultationRequest;
|
||||
use App\Models\Consultation;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ConsultationController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$status = ConsultationStatus::tryFrom((string) $request->query('status'));
|
||||
|
||||
return Inertia::render('admin/consultations/index', [
|
||||
'consultations' => Consultation::query()
|
||||
->when($status, fn ($query) => $query->where('status', $status))
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString(),
|
||||
'status' => $status?->value,
|
||||
'counts' => Consultation::query()
|
||||
->selectRaw('status, count(*) as total')
|
||||
->groupBy('status')
|
||||
->pluck('total', 'status'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateConsultationRequest $request, Consultation $consultation): RedirectResponse
|
||||
{
|
||||
$consultation->update($request->validated());
|
||||
|
||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Permintaan konsultasi diperbarui.']);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy(Consultation $consultation): RedirectResponse
|
||||
{
|
||||
$consultation->delete();
|
||||
|
||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Permintaan konsultasi dihapus.']);
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user