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.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Immagini del configuratore salvate sul disco public: rimuove i file sostituiti o del
|
||||
* record eliminato. Ogni record ha percorsi propri, quindi nessun file è condiviso.
|
||||
*
|
||||
* Il modello dichiara le colonne con `protected static array $immagini = [...]`.
|
||||
*/
|
||||
trait HaImmaginiCatalogo
|
||||
{
|
||||
protected static function bootHaImmaginiCatalogo(): void
|
||||
{
|
||||
static::updated(function ($record): void {
|
||||
foreach (static::$immagini as $colonna) {
|
||||
$vecchia = $record->getOriginal($colonna);
|
||||
if ($record->wasChanged($colonna) && $vecchia) {
|
||||
Storage::disk('public')->delete($vecchia);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(function ($record): void {
|
||||
$file = array_filter(array_map(fn ($c) => $record->{$c}, static::$immagini));
|
||||
Storage::disk('public')->delete($file);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user