'array', 'date_devis' => 'date', 'total_ht' => 'decimal:2', 'total_ttc' => 'decimal:2', 'tva_rate' => 'decimal:2', ]; public function parent(): BelongsTo { return $this->belongsTo(Devis::class, 'parent_devis_id'); } public function sousDevis(): HasMany { return $this->hasMany(Devis::class, 'parent_devis_id'); } public function commande(): BelongsTo { return $this->belongsTo(\App\Models\Order::class, 'commande_id'); } protected static function booted() { static::creating(function ($devis) { if (empty($devis->number)) { $year = date('Y'); $prefix = sprintf('DEV-%s-', $year); $last = static::where('number', 'like', $prefix . '%') ->max('number'); $next = $last ? (intval(substr($last, strlen($prefix))) + 1) : 1; $devis->number = $prefix . sprintf('%04d', $next); } }); } }