init
This commit is contained in:
32
web10/app/Models/SiteSetting.php
Normal file
32
web10/app/Models/SiteSetting.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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}");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user