Files
carmine.savino 06617a985a feat: add previous configuration handling for user selections in quotes
- Implemented session storage management for the last configuration choices made by the user.
- Added functionality to prompt users when changing models to retain their previous selections.
- Introduced methods to apply previous choices to the newly loaded model, including finishes, handles, glass types, and options.
- Enhanced user experience by ensuring selections are automatically applied where applicable.
2026-10-19 19:49:44 +02:00

59 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\HaImmaginiCatalogo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Vetro extends Model
{
use HaImmaginiCatalogo;
protected $table = 'vetri';
protected static array $immagini = ['anteprima', 'popup', 'texture', 'texture_bump'];
protected $fillable = [
'sistema_id', 'codice', 'descrizione', 'maggiorazione_mq', 'minimo_mq',
'colore', 'roughness', 'metalness', 'opacita', 'anteprima', 'popup', 'texture',
'texture_bump', 'bump_scala', 'predefinito', 'ordine', 'attivo',
];
protected $casts = [
'maggiorazione_mq' => 'float',
'minimo_mq' => 'float',
'roughness' => 'float',
'metalness' => 'float',
'opacita' => 'float',
'bump_scala' => 'float',
'predefinito' => 'boolean',
'ordine' => 'integer',
'attivo' => 'boolean',
];
public function sistema(): BelongsTo
{
return $this->belongsTo(Sistema::class);
}
public function scopeAttivi(Builder $query): Builder
{
return $query->where('attivo', true)->orderBy('ordine')->orderBy('id');
}
protected static function booted(): void
{
// Un solo elemento predefinito per sistema.
static::saved(function (self $record): void {
if ($record->predefinito && ($record->wasRecentlyCreated || $record->wasChanged('predefinito'))) {
static::query()
->where('sistema_id', $record->sistema_id)
->whereKeyNot($record->getKey())
->update(['predefinito' => false]);
}
});
}
}