Certified/app/Http/Controllers/LanguageController.php
Joël van de Wouw ac340d125c
Some checks failed
linter / quality (push) Failing after 13s
tests / ci (8.3) (push) Failing after 2s
tests / ci (8.4) (push) Failing after 2s
tests / ci (8.5) (push) Failing after 3s
Initial commit
Certificate manager built on Laravel 13, Livewire 4, and Flux.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 14:44:58 +02:00

29 lines
766 B
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\Locale;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class LanguageController extends Controller
{
/**
* Switch the active language. Persisted to the user's account when
* authenticated, otherwise kept in the session for the duration of the
* guest visit (e.g. while browsing the login/register pages).
*/
public function __invoke(Request $request, string $locale): RedirectResponse
{
abort_unless(in_array($locale, Locale::values(), true), 404);
session(['locale' => $locale]);
if ($request->user()) {
$request->user()->locale = $locale;
$request->user()->save();
}
return back();
}
}