33 lines
731 B
PHP
33 lines
731 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class SiteSetting extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'key',
|
||
|
|
'value',
|
||
|
|
];
|
||
|
|
|
||
|
|
public static function value(string $key, $default = null)
|
||
|
|
{
|
||
|
|
return cache()->remember("site_setting_{$key}", 600, function () use ($key, $default) {
|
||
|
|
$setting = static::where('key', $key)->first();
|
||
|
|
|
||
|
|
return $setting?->value ?? $default;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
protected static function booted()
|
||
|
|
{
|
||
|
|
static::saved(function (SiteSetting $setting): void {
|
||
|
|
cache()->forget("site_setting_{$setting->key}");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|