structure changes
This commit is contained in:
@@ -3,25 +3,79 @@
|
||||
namespace Modules\Settings\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Settings\Models\Setting;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Settings\Services\SettingsRepository;
|
||||
|
||||
final class SettingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(SettingsRepository $settings): View
|
||||
{
|
||||
$settings = Setting::query()->orderBy('group')->orderBy('key')->get();
|
||||
|
||||
return view('settings::index', compact('settings'));
|
||||
return view('settings::index', [
|
||||
'values' => $settings->site(),
|
||||
'sections' => $this->sections(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
public function update(Request $request, SettingsRepository $settings): RedirectResponse
|
||||
{
|
||||
$data = $request->validate(['settings' => ['array'], 'settings.*' => ['nullable', 'string', 'max:5000']]);
|
||||
foreach ($data['settings'] ?? [] as $id => $value) {
|
||||
Setting::whereKey($id)->update(['value' => $value]);
|
||||
$rules = [];
|
||||
foreach ($this->sections() as $fields) {
|
||||
foreach ($fields as $key => $definition) {
|
||||
$rules["settings.$key"] = $definition['rules'];
|
||||
}
|
||||
}
|
||||
|
||||
return back()->with('status', 'Settings saved.');
|
||||
$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.'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user