Files
InvoiceShelf/app/Platform/Operations/Models/Setting.php
T
Darko Gjorgjijoski 5ef7804e60 refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
2026-08-05 17:40:03 +02:00

80 lines
1.8 KiB
PHP

<?php
namespace App\Platform\Operations\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class Setting extends Model
{
protected $table = 'settings';
use HasFactory;
protected $fillable = ['option', 'value'];
/**
* Create or update a single application setting by key.
*/
public static function setSetting(string $key, mixed $setting): void
{
$old = self::whereOption($key)->first();
if ($old) {
$old->value = $setting;
$old->save();
return;
}
$set = new Setting;
$set->option = $key;
$set->value = $setting;
$set->save();
}
/**
* Bulk create or update application settings from a key-value array.
*/
public static function setSettings(array $settings): void
{
foreach ($settings as $key => $value) {
self::updateOrCreate(
[
'option' => $key,
],
[
'option' => $key,
'value' => $value,
]
);
}
}
/**
* Retrieve a single setting value by key, or null if not found.
*/
public static function getSetting(string $key): mixed
{
$setting = static::whereOption($key)->first();
if ($setting) {
return $setting->value;
} else {
return null;
}
}
/**
* Retrieve multiple settings as a key-value collection.
*/
public static function getSettings(array $settings): Collection
{
return static::whereIn('option', $settings)
->get()->mapWithKeys(function ($item) {
return [$item['option'] => $item['value']];
});
}
}