45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
// Model Setting — gestisce le impostazioni dinamiche dell'applicazione
|
|
//
|
|
// Ogni riga della tabella `settings` è una coppia chiave-valore.
|
|
// Esempio:
|
|
// key: "items_per_page" value: "15"
|
|
// key: "currency_symbol" value: "€"
|
|
//
|
|
// I valori sono sempre stringhe nel DB. SettingService gestisce il cast
|
|
// al tipo corretto (int, bool, string, ecc.) basandosi su config/settings.php
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Setting extends Model
|
|
{
|
|
protected $table = 'settings';
|
|
|
|
protected $fillable = [
|
|
'key',
|
|
'value',
|
|
'label', // Nome leggibile mostrato nel pannello admin
|
|
'group', // Gruppo di appartenenza (es. "Azienda", "Visualizzazione")
|
|
'type', // Tipo dato: string, integer, boolean, text
|
|
];
|
|
|
|
// Non usiamo timestamps per le impostazioni (semplifica la tabella)
|
|
public $timestamps = true;
|
|
|
|
// ─── Scope: cerca per chiave ──────────────────────────────────────────
|
|
public function scopeForKey($query, string $key)
|
|
{
|
|
return $query->where('key', $key);
|
|
}
|
|
|
|
public function scopeInGroup($query, string $group)
|
|
{
|
|
return $query->where('group', $group);
|
|
}
|
|
}
|