<?php

namespace Sartoric\ModularCms\Models;

use Illuminate\Support\Facades\Schema;

class Setting extends McmsModel
{
//    public static function settings()
//    {
//        return  null;
//    }

    public $timestamps = false;

    protected $table = 'sys_settings';

    public static function appsettings()
    {
        return Setting::where('user_id', 0)
//                        ->where('active', true)
            ->get();
    }

    public static function appSetting($setId)
    {
        $appsetting = null;
        // check if table exists to avois issues with fresh installation (web routes won't work)
        if (Schema::hasTable('sys_settings')) {
            $appsetting = Setting::where('user_id', 0)
                ->where('setting', $setId)
                ->first();
        }
        if (empty($appsetting)) {
            $appsetting = config('app.'.$setId);

            return $appsetting;
        } else {
            return $appsetting->value;
        }
    }

}
