20-02-2026
This commit is contained in:
parent
854ce02bf6
commit
4d6b4930b2
128 changed files with 18247 additions and 2093 deletions
55
app/Models/Setting.php
Normal file
55
app/Models/Setting.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'group',
|
||||
'key',
|
||||
'value',
|
||||
'type',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* Hole einen Setting-Wert anhand von Gruppe und Key.
|
||||
*/
|
||||
public static function getValue(string $group, string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = self::query()
|
||||
->where('group', $group)
|
||||
->where('key', $key)
|
||||
->first();
|
||||
|
||||
if (! $setting) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return match ($setting->type) {
|
||||
'integer' => (int) $setting->value,
|
||||
'boolean' => filter_var($setting->value, FILTER_VALIDATE_BOOLEAN),
|
||||
'json' => json_decode($setting->value, true),
|
||||
default => $setting->value,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Setze einen Setting-Wert.
|
||||
*/
|
||||
public static function setValue(string $group, string $key, mixed $value): void
|
||||
{
|
||||
$setting = self::query()
|
||||
->where('group', $group)
|
||||
->where('key', $key)
|
||||
->first();
|
||||
|
||||
if ($setting) {
|
||||
$setting->update([
|
||||
'value' => is_array($value) ? json_encode($value) : (string) $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue