'date', 'sort_order' => 'integer', 'metadati' => 'array', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; public const TIPI = [ 'documento' => 'Documento cartaceo', 'foglio' => 'Foglio / documento singolo', 'cartellina' => 'Cartellina', 'busta_trasparente' => 'Busta trasparente con anelli da archiviare', 'cartella_tre_lembi' => 'Cartella a tre lembi', 'faldone_anelli' => 'Faldone con anelli', 'faldone_lacci' => 'Faldone con lacci', 'scatola' => 'Scatola', 'scaffale' => 'Scaffale', 'posto' => 'Posto / ubicazione finale', ]; public function stabile(): BelongsTo { return $this->belongsTo(Stabile::class, 'stabile_id'); } public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_id'); } public function children(): HasMany { return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('titolo'); } public function documento(): BelongsTo { return $this->belongsTo(Documento::class, 'documento_id'); } public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); } public function getTipoLabelAttribute(): string { return self::TIPI[$this->tipo_item] ?? $this->tipo_item; } public function getPercorsoFisicoAttribute(): string { $parts = []; $current = $this; while ($current instanceof self) { $parts[] = trim($current->codice_univoco . ' ' . $current->titolo); $current = $current->parent; } return implode(' / ', array_reverse(array_filter($parts))); } public function getQrCodeImageAttribute(): string { $data = $this->buildQrPayload(); if ($data !== '' && class_exists(\chillerlan\QRCode\QROptions::class) && class_exists(\chillerlan\QRCode\QRCode::class)) { $options = new \chillerlan\QRCode\QROptions([ 'outputType' => \chillerlan\QRCode\QRCode::OUTPUT_MARKUP_SVG, 'eccLevel' => \chillerlan\QRCode\QRCode::ECC_M, 'addQuietzone' => true, 'quietzoneSize' => 1, 'connectPaths' => true, ]); $svg = (new \chillerlan\QRCode\QRCode($options))->render($data); if (str_starts_with($svg, 'data:image/svg+xml;base64,')) { $decoded = base64_decode(substr($svg, strlen('data:image/svg+xml;base64,')), true); if (is_string($decoded) && $decoded !== '') { $svg = $decoded; } } return str_contains($svg, '