58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin\Settings;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Requests\Admin\Settings\UpdateSettingRequest;
|
||
|
|
use App\Services\SettingService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Controller to handle updating site-wide settings.
|
||
|
|
*/
|
||
|
|
class SettingUpdateController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Update the site settings.
|
||
|
|
*
|
||
|
|
* @param UpdateSettingRequest $request
|
||
|
|
* @param SettingService $settingService
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function __invoke(UpdateSettingRequest $request, SettingService $settingService)
|
||
|
|
{
|
||
|
|
$validated = $request->validated();
|
||
|
|
|
||
|
|
// Group settings appropriately
|
||
|
|
$general = [
|
||
|
|
'site_title' => $validated['site_title'],
|
||
|
|
];
|
||
|
|
|
||
|
|
$seo = [
|
||
|
|
'seo_description' => $validated['seo_description'] ?? '',
|
||
|
|
'seo_keywords' => $validated['seo_keywords'] ?? [],
|
||
|
|
];
|
||
|
|
|
||
|
|
$localization = [
|
||
|
|
'supported_languages' => $validated['supported_languages'],
|
||
|
|
'default_locale' => $validated['default_locale'],
|
||
|
|
];
|
||
|
|
|
||
|
|
$translation = [
|
||
|
|
'translation_driver' => $validated['translation_driver'],
|
||
|
|
'google_translate_key' => $validated['google_translate_key'] ?? '',
|
||
|
|
];
|
||
|
|
|
||
|
|
// Update settings via service
|
||
|
|
$settingService->updateSettings($general, 'general');
|
||
|
|
$settingService->updateSettings($seo, 'seo');
|
||
|
|
$settingService->updateSettings($localization, 'localization');
|
||
|
|
$settingService->updateSettings($translation, 'translation');
|
||
|
|
|
||
|
|
if ($request->wantsJson()) {
|
||
|
|
return response()->json(['status' => 'Settings updated successfully.']);
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('status', 'Settings updated successfully.');
|
||
|
|
}
|
||
|
|
}
|