| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Setting extends Model
- {
- public const KEY_DEFAULT_MAF_ORDER_USER_ID = 'default_maf_order_user_id';
- public const KEY_RECLAMATION_ACT_REPRESENTATIVE_USER_ID = 'reclamation_act_representative_user_id';
- protected $fillable = [
- 'key',
- 'value',
- ];
- public static function get(string $key, mixed $default = null): mixed
- {
- $value = static::query()->where('key', $key)->value('value');
- return $value ?? $default;
- }
- public static function getInt(string $key, ?int $default = null): ?int
- {
- $value = static::get($key, $default);
- if ($value === null || $value === '') {
- return $default;
- }
- return (int) $value;
- }
- public static function set(string $key, mixed $value): void
- {
- static::query()->updateOrCreate(
- ['key' => $key],
- ['value' => $value === null ? null : (string) $value]
- );
- }
- }
|