初始化
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$settings = Setting::pluck('value', 'key')->toArray();
|
||||
|
||||
return view('admin.settings', compact('settings'));
|
||||
}
|
||||
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'site_name' => ['required', 'string', 'max:80'],
|
||||
'site_description' => ['nullable', 'string', 'max:255'],
|
||||
'seo_title_default' => ['nullable', 'string', 'max:160'],
|
||||
'seo_description_default' => ['nullable', 'string', 'max:255'],
|
||||
'icp_no' => ['nullable', 'string', 'max:60'],
|
||||
'security_filing_no' => ['nullable', 'string', 'max:60'],
|
||||
'logo_url' => ['nullable', 'string', 'max:255'],
|
||||
'favicon_url' => ['nullable', 'string', 'max:255'],
|
||||
'contact_email' => ['nullable', 'email', 'max:120'],
|
||||
'theme' => ['nullable', 'string', 'in:azure,slate,indigo,teal,amber'],
|
||||
'footer_content' => ['nullable', 'string', 'max:20000'],
|
||||
]);
|
||||
|
||||
$seoKeys = ['site_description', 'seo_title_default', 'seo_description_default'];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$group = in_array($key, $seoKeys, true) ? 'seo' : 'general';
|
||||
Setting::set($key, $value ?: null, $group);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.settings')->with('success', '站点设置已保存');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user