cms/app/Models/Setting.php
Funky Waddle 37ed997989 feat(cms): initialize Laravel project structure and core CMS files
- Added standard Laravel directory structure and configuration.

- Included Svelte and Tailwind configuration for the admin interface.

- Added core PHPUnit and testing scripts.
2026-04-13 12:48:06 -05:00

39 lines
850 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
protected $fillable = ['key', 'value', 'group'];
protected function casts(): array
{
return [
'value' => 'array',
];
}
/**
* Get a setting value by key.
*/
public static function get(string $key, $default = null)
{
try {
$setting = self::where('key', $key)->first();
return $setting ? $setting->value : $default;
} catch (\Illuminate\Database\QueryException $e) {
return $default;
}
}
/**
* Set a setting value.
*/
public static function set(string $key, $value, string $group = 'general')
{
return self::updateOrCreate(['key' => $key], ['value' => $value, 'group' => $group]);
}
}