59 lines
No EOL
1.3 KiB
PHP
59 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property array<string, mixed>|null $data
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
*/
|
|
class GeneralConfig extends Model
|
|
{
|
|
|
|
protected $fillable = ['data'];
|
|
|
|
protected $casts = [
|
|
'data' => 'array',
|
|
];
|
|
|
|
/**
|
|
* Get the unique configuration row.
|
|
*
|
|
* @return self
|
|
*/
|
|
public static function current(): self
|
|
{
|
|
return static::query()->firstOrCreate([], ['data' => []]);
|
|
}
|
|
|
|
/**
|
|
* Get a setting value from the JSON data.
|
|
*
|
|
* @param string $key Setting key.
|
|
* @param mixed $default Value returned.
|
|
* @return mixed
|
|
*/
|
|
public function get(string $key, mixed $default = null): mixed
|
|
{
|
|
return data_get($this->data, $key, $default);
|
|
}
|
|
|
|
/**
|
|
* Set a setting value in the JSON data.
|
|
*
|
|
* @param string $key Setting key.
|
|
* @param mixed $value Value to store.
|
|
* @return self
|
|
*/
|
|
public function put(string $key, mixed $value): self
|
|
{
|
|
$data = $this->data ?? [];
|
|
data_set($data, $key, $value);
|
|
$this->data = $data;
|
|
|
|
return $this;
|
|
}
|
|
} |