Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sanjayacloud's avatar

Generate Invoice number In larvel to predefined specific format

Hi Everyone, I am trying to generate invoice numbers automatically in laravel with predefined formate. Formate as follows. I don't know how to do that. Anyone can help me to do that. The invoice number should be started from "AT000001" and it should be increment.

0 likes
3 replies
tykus's avatar

If you have a database table for your invoices (with a conventional auto-incrementing id), then you can make an accessor on the Invoice model to get the invoice number in the format you prefer.

// Invoice Model
public function getNumberAttribute()
{
	return 'AT' . str_pad($this->id, 6, 0, STR_PAD_LEFT)

}

You can also find the Invoice by number by using a static:

public function findByNumber($number)
{
	$id = intval(\Str::after($number, 'AT'));

	return static::find($id); 
}

Please or to participate in this conversation.