Files
go-no-go/app/Http/Controllers/ScreeningController.php

57 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Screening;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
final class ScreeningController extends Controller
{
/**
* Create a new screening session for the authenticated user.
*/
public function store(Request $request): RedirectResponse
{
$screening = Screening::create([
'user_id' => auth()->id(),
]);
return redirect()->route('screening.show', $screening);
}
/**
* Display the screening questionnaire.
*/
public function show(Screening $screening): Response
{
return Inertia::render('Screening/Show', [
'screening' => $screening,
]);
}
/**
* Save screening answers and redirect to result.
*/
public function update(Request $request, Screening $screening): RedirectResponse
{
return redirect()->route('screening.result', $screening);
}
/**
* Display the screening result with available categories.
*/
public function result(Screening $screening): Response
{
return Inertia::render('Screening/Result', [
'screening' => $screening,
'categories' => Category::orderBy('sort_order')->get(['id', 'name']),
]);
}
}