<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models;
use Session;
use DB;
use App\ActivityLog;

class SettingsController extends Controller
{
    public function index()
    {
        $settings = Models\Settings::get();
        // dd($settings);
        $data = [
            'settings' => $settings,
             'page_title' => 'System Settings'
        ];
        return view('super_admin.settings',$data);
    }

    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'value' => 'required',
            'id' => 'required'
        ]);

        $name = $request->input('name');
        $value = $request->input('value');

        $settings = Models\Settings::find($id);
        if ($settings) {
            $settings->name = $value;
            $settings->save();
        } else {
            Models\Settings::create([
                'name' => $name,
                'value' => $value
            ]);
        }

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