Files
ABSDEV/Modules/Settings/Http/Controllers/SettingController.php
T
2026-07-27 14:17:30 +01:00

82 lines
3.6 KiB
PHP

<?php
namespace Modules\Settings\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Settings\Services\SettingsRepository;
final class SettingController extends Controller
{
public function index(SettingsRepository $settings): View
{
return view('settings::index', [
'values' => $settings->site(),
'sections' => $this->sections(),
]);
}
public function update(Request $request, SettingsRepository $settings): RedirectResponse
{
$rules = [];
foreach ($this->sections() as $fields) {
foreach ($fields as $key => $definition) {
$rules["settings.$key"] = $definition['rules'];
}
}
$validated = $request->validate($rules);
foreach ($validated['settings'] ?? [] as $key => $value) {
$settings->put($key, $value, 'site', 'string', true);
}
return back()->with('status', 'Site settings saved. The frontend has been updated everywhere.');
}
/** @return array<string, array<string, array<string, mixed>>> */
private function sections(): array
{
$text = ['type' => 'text', 'rules' => ['nullable', 'string', 'max:255']];
$url = ['type' => 'text', 'rules' => ['nullable', 'string', 'max:2048'], 'placeholder' => '/path or https://example.com'];
$textarea = ['type' => 'textarea', 'rules' => ['nullable', 'string', 'max:5000']];
return [
'General' => [
'site_name' => $text + ['label' => 'Site name', 'help' => 'Used in the header, footer, browser titles and metadata.'],
'tagline' => $text + ['label' => 'Tagline'],
'site_description' => $textarea + ['label' => 'Site description'],
'company_name' => $text + ['label' => 'Legal company name'],
'site_url' => $url + ['label' => 'Canonical site URL'],
'copyright' => $text + ['label' => 'Copyright text', 'help' => 'Leave blank to generate it automatically.'],
],
'Branding' => [
'logo_url' => $url + ['label' => 'Primary logo'],
'logo_dark_url' => $url + ['label' => 'Dark-mode logo'],
'favicon_url' => $url + ['label' => 'Favicon'],
],
'Contact' => [
'contact_email' => ['type' => 'email', 'rules' => ['nullable', 'email', 'max:255'], 'label' => 'Public email'],
'contact_phone' => $text + ['label' => 'Public telephone'],
'address' => $textarea + ['label' => 'Address'],
],
'Social' => [
'facebook_url' => $url + ['label' => 'Facebook'],
'x_url' => $url + ['label' => 'X / Twitter'],
'linkedin_url' => $url + ['label' => 'LinkedIn'],
'instagram_url' => $url + ['label' => 'Instagram'],
],
'Account navigation' => [
'dashboard_label' => $text + ['label' => 'Dashboard label'],
'login_label' => $text + ['label' => 'Login label'],
'registration_label' => $text + ['label' => 'Registration label'],
],
'SEO defaults' => [
'default_meta_title' => $text + ['label' => 'Default meta title', 'help' => 'Leave blank to use the site name.'],
'default_meta_description' => $textarea + ['label' => 'Default meta description', 'help' => 'Leave blank to use the site description.'],
],
];
}
}