<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;

class SiteSetting extends Model
{
    protected $table = 'site_settings';
    protected $fillable = ['setting_key', 'setting_value'];
    public $timestamps = false;

    public static function get($key, $default = null)
    {
        $row = DB::table('site_settings')->where('setting_key', $key)->first();
        return $row ? $row->setting_value : $default;
    }

    public static function set($key, $value)
    {
        DB::table('site_settings')->updateOrInsert(
            ['setting_key' => $key],
            ['setting_value' => $value, 'updated_at' => date('Y-m-d H:i:s')]
        );
    }

    public static function getAll()
    {
        return DB::table('site_settings')->pluck('setting_value', 'setting_key')->toArray();
    }
}
