ifnex/04_Laravel/app/Models/SystemSetting.php
Kazem Alghasi a59e192b32 ۱۰ مورد کامل شد (دیتابیس، مدل‌ها، API، Filament، Laravel 11، رفع باگ‌ها)
🔄 در حال انجام: تست دستی Filament
⏸️ بلاک: مهاجرت ۳۹۵۰ رکورد (منتظر فایل اکسل اصلاح‌شده)
⏸️ بلاک: پلاگین وردپرس (بعد از تست کامل API)
2026-08-04 01:59:08 +03:30

47 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SystemSetting extends Model
{
protected $fillable = [
'key',
'value',
'description',
'updated_by',
];
protected function casts(): array
{
return [
'value' => 'decimal:4',
];
}
public function updatedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
public static function get(string $key, $default = null)
{
$setting = static::where('key', $key)->first();
return $setting ? $setting->value : $default;
}
public static function set(string $key, $value, ?string $description = null, ?int $updatedBy = null): void
{
static::updateOrCreate(
['key' => $key],
[
'value' => $value,
'description' => $description,
'updated_by' => $updatedBy,
]
);
}
}