'array', 'date_devis' => 'date', 'total_ht' => 'decimal:2', 'total_ttc' => 'decimal:2', 'tva_rate' => 'decimal:2', ]; 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); } }); } }