mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-11-03 14:03:18 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Crater\Models;
 | 
						|
 | 
						|
use Illuminate\Database\Eloquent\Factories\HasFactory;
 | 
						|
use Illuminate\Database\Eloquent\Model;
 | 
						|
 | 
						|
class Setting extends Model
 | 
						|
{
 | 
						|
    use HasFactory;
 | 
						|
 | 
						|
    protected $fillable = ['option', 'value'];
 | 
						|
 | 
						|
    public static function setSetting($key, $setting)
 | 
						|
    {
 | 
						|
        $old = self::whereOption($key)->first();
 | 
						|
 | 
						|
        if ($old) {
 | 
						|
            $old->value = $setting;
 | 
						|
            $old->save();
 | 
						|
 | 
						|
            return;
 | 
						|
        }
 | 
						|
 | 
						|
        $set = new Setting();
 | 
						|
        $set->option = $key;
 | 
						|
        $set->value = $setting;
 | 
						|
        $set->save();
 | 
						|
    }
 | 
						|
 | 
						|
    public static function setSettings($settings)
 | 
						|
    {
 | 
						|
        foreach ($settings as $key => $value) {
 | 
						|
            self::updateOrCreate(
 | 
						|
                [
 | 
						|
                    'option' => $key,
 | 
						|
                ],
 | 
						|
                [
 | 
						|
                    'option' => $key,
 | 
						|
                    'value' => $value,
 | 
						|
                ]
 | 
						|
            );
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getSetting($key)
 | 
						|
    {
 | 
						|
        $setting = static::whereOption($key)->first();
 | 
						|
 | 
						|
        if ($setting) {
 | 
						|
            return $setting->value;
 | 
						|
        } else {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getSettings($settings)
 | 
						|
    {
 | 
						|
        return static::whereIn('option', $settings)
 | 
						|
            ->get()->mapWithKeys(function ($item) {
 | 
						|
                return [$item['option'] => $item['value']];
 | 
						|
            });
 | 
						|
    }
 | 
						|
}
 |