<?php

namespace App\Http\Controllers\Web\Admin;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\Request;

class AdminSettingController extends Controller
{
    public function index()
    {
        $settings = Setting::all()->groupBy('group');
        return view('admin.settings.index', compact('settings'));
    }

    public function update(Request $request)
    {
        $settings = $request->input('settings.value', []);

        foreach ($settings as $key => $value) {
            Setting::setValue($key, $value, 'string', 'general');
        }

        return back()->with('success', 'Settings updated');
    }
}
