Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HelpController
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 index
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 update
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace App\Http\Controllers\admin;
4
5use App\Http\Controllers\Controller;
6use Illuminate\Http\RedirectResponse;
7use Illuminate\Http\Request;
8use Illuminate\View\View;
9
10/**
11 * Settings → Help texts. Reword any of the little "?" hints shown around
12 * the admin panel. Overrides are stored as `help.<key>` settings and read
13 * back by the <x-ui.help> component.
14 */
15class HelpController extends Controller
16{
17    public function index(): View
18    {
19        $registry = collect(config('help', []))
20            ->map(fn ($def, $key) => [
21                'key' => $key,
22                'group' => $def['group'] ?? 'General',
23                'label' => $def['label'] ?? $key,
24                'default' => $def['default'] ?? '',
25                'current' => settings("help.$key", $def['default'] ?? ''),
26                'overridden' => settings()->has("help.$key"),
27            ])
28            ->groupBy('group');
29
30        return view('admin.help.index', ['groups' => $registry]);
31    }
32
33    public function update(Request $request): RedirectResponse
34    {
35        $texts = (array) $request->input('help', []);
36
37        foreach (array_keys(config('help', [])) as $key) {
38            $value = trim((string) ($texts[$key] ?? ''));
39            $default = (string) config("help.$key.default", '');
40
41            // Store an override only when it differs from the built-in text.
42            settings()->set("help.$key", ($value === '' || $value === $default) ? null : $value);
43        }
44
45        return redirect()->route('admin.help.index')->with('success', 'Help texts saved.');
46    }
47}