first commit
This commit is contained in:
44
app/Http/Controllers/Admin/AppConfigController.php
Normal file
44
app/Http/Controllers/Admin/AppConfigController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AppConfig;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AppConfigController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// 確保預設設定存在
|
||||
$defaults = [
|
||||
'ui_primary_color' => ['value' => '#4F46E5', 'group' => 'ui', 'type' => 'string'],
|
||||
'ui_logo_url' => ['value' => '', 'group' => 'ui', 'type' => 'string'],
|
||||
'helper_enabled' => ['value' => '1', 'group' => 'helper', 'type' => 'boolean'],
|
||||
'game_enabled' => ['value' => '0', 'group' => 'game', 'type' => 'boolean'],
|
||||
'questionnaire_url' => ['value' => '', 'group' => 'game', 'type' => 'string'],
|
||||
];
|
||||
|
||||
foreach ($defaults as $key => $data) {
|
||||
AppConfig::firstOrCreate(['key' => $key], $data);
|
||||
}
|
||||
|
||||
$configs = AppConfig::all()->groupBy('group');
|
||||
|
||||
return view('admin.app-configs.index', compact('configs'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$data = $request->except('_token', '_method');
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
AppConfig::updateOrCreate(
|
||||
['key' => $key],
|
||||
['value' => $value]
|
||||
);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', '設定已更新');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user