'integer', 'created_at' => 'datetime', ]; const TYPES_LABELS = [ 'devis' => 'Devis', 'bon_commande' => 'Bon de commande', 'bon_livraison' => 'Bon de livraison', 'facture' => 'Facture', 'contrat' => 'Contrat', 'avenant' => 'Avenant', 'autre' => 'Autre', ]; const TYPES_ICONES = [ 'devis' => 'πŸ“‹', 'bon_commande' => 'πŸ›’', 'bon_livraison' => 'πŸ“¦', 'facture' => '🧾', 'contrat' => 'πŸ“„', 'avenant' => 'πŸ“‘', 'autre' => 'πŸ“Ž', ]; const TYPES_COULEURS = [ 'devis' => 'purple', 'bon_commande' => 'blue', 'bon_livraison' => 'orange', 'facture' => 'green', 'contrat' => 'indigo', 'avenant' => 'teal', 'autre' => 'gray', ]; // ----------------------------------------------------------------------- // Relations // ----------------------------------------------------------------------- public function commande(): BelongsTo { return $this->belongsTo(Commande::class); } public function contrat(): BelongsTo { return $this->belongsTo(Contrat::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } // ----------------------------------------------------------------------- // Accesseurs // ----------------------------------------------------------------------- public function getTypeLabelAttribute(): string { return self::TYPES_LABELS[$this->type] ?? $this->type; } public function getTailleFormatteeAttribute(): string { $taille = $this->taille; if ($taille < 1024) { return $taille . ' o'; } elseif ($taille < 1024 * 1024) { return round($taille / 1024, 1) . ' Ko'; } return round($taille / (1024 * 1024), 1) . ' Mo'; } public function getEstImageAttribute(): bool { return str_starts_with($this->mime_type, 'image/'); } public function getEstPdfAttribute(): bool { return $this->mime_type === 'application/pdf'; } // ----------------------------------------------------------------------- // MΓ©thodes // ----------------------------------------------------------------------- public function supprimer(): void { Storage::disk('private')->delete($this->chemin); $this->delete(); } }