346fcf968f
Filament pages wrap their content in an outer <form>. My inline <form method="POST"> for the hint toggle + reset was nested inside that outer form — invalid HTML, so browsers dropped my submit and either did nothing or ran the outer Livewire form's handler. Replaced both forms with plain <button type="button"> + onclick fetch() POST + window.location.reload(). Controller now also returns JSON when Accept: application/json (fetch sends that) instead of a back() redirect. The server-side flip was always correct — verified via a Feature test that posts to /app/hints/toggle and asserts the user column flipped from true → false. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class HintController extends Controller
|
|
{
|
|
public function dismiss(Request $request, string $key)
|
|
{
|
|
$user = $request->user();
|
|
abort_unless($user, 401);
|
|
$dismissed = (array) ($user->dismissed_hints ?? []);
|
|
if (! in_array($key, $dismissed, true)) {
|
|
$dismissed[] = $key;
|
|
$user->dismissed_hints = $dismissed;
|
|
$user->save();
|
|
}
|
|
return response()->json(['ok' => true]);
|
|
}
|
|
|
|
/** Toggle global hints on/off from the profile / settings page. */
|
|
public function toggle(Request $request)
|
|
{
|
|
$user = $request->user();
|
|
abort_unless($user, 401);
|
|
$user->hints_enabled = ! $user->hints_enabled;
|
|
$user->save();
|
|
if ($request->expectsJson()) {
|
|
return response()->json(['ok' => true, 'hints_enabled' => (bool) $user->hints_enabled]);
|
|
}
|
|
return back();
|
|
}
|
|
|
|
/** Bring back all dismissed hints (used from FAQ / profile "resetează hint-uri"). */
|
|
public function reset(Request $request)
|
|
{
|
|
$user = $request->user();
|
|
abort_unless($user, 401);
|
|
$user->dismissed_hints = [];
|
|
$user->hints_enabled = true;
|
|
$user->save();
|
|
if ($request->expectsJson()) {
|
|
return response()->json(['ok' => true]);
|
|
}
|
|
return back();
|
|
}
|
|
}
|