init
This commit is contained in:
236 files changed
+24692
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user