Files
2026-11-26 12:29:14 +03:30

36 lines
774 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
public const STUDIO_PUBLIC_INFORMATION = 'studio.public_information';
protected $primaryKey = 'key';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = ['key', 'value'];
protected function casts(): array
{
return ['value' => 'json'];
}
public static function read(string $key, mixed $default = null): mixed
{
$setting = static::query()->find($key);
return $setting === null ? $default : $setting->value;
}
public static function write(string $key, mixed $value): void
{
static::query()->updateOrCreate(['key' => $key], ['value' => $value]);
}
}