ldc-cocotte/app/Models/Setting.php

53 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace App\Models;
use App\Casts\EmployeeSitesCast;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string[]|null $employee_sites
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*
* @mixin \Eloquent
*/
class Setting extends Model
{
public const int SINGLETON_ID = 1;
protected $fillable = [
'employee_sites',
];
/**
* @return array<string, class-string|string>
*/
#[\Override]
protected function casts(): array
{
return [
'employee_sites' => EmployeeSitesCast::class,
];
}
public static function getSingleton(): self
{
$setting = self::query()->find(self::SINGLETON_ID);
if ($setting !== null) {
return $setting;
}
$setting = new self();
$setting->id = self::SINGLETON_ID;
$setting->employee_sites = [];
$setting->save();
return $setting;
}
}