invoice number in a field

Hi everyone, I'm new in filament, i want to ask how to create invoice/ sales order number filed bases on squence : PMP/month/year/number_invoice And it's automatically increment Like the photo Best regard
No description
2 Replies
oxodesign
oxodesign2w ago
Do you need to display it before you create it? - In this case use default with Closure and get the data/logic from db. Otherwise use the mutateFormDataBeforeCreate hook
Hik
Hik2w ago
this is if you want to create it after the record is saved in the db. User model:
public static function boot()
{
parent::boot();

self::creating(function ($model) {
// ... code here
});

self::created(function ($model) {
// USER00001
$model->special_identifier = 'USER' . str_pad($model->id, 5, '0', STR_PAD_LEFT);

$model->save(); // You need to save again since this happens after creation
});

self::updating(function ($model) {
// ... code here
});

self::updated(function ($model) {
// ... code here
});

self::deleting(function ($model) {
// ... code here
});

self::deleted(function ($model) {
// ... code here
});
}
public static function boot()
{
parent::boot();

self::creating(function ($model) {
// ... code here
});

self::created(function ($model) {
// USER00001
$model->special_identifier = 'USER' . str_pad($model->id, 5, '0', STR_PAD_LEFT);

$model->save(); // You need to save again since this happens after creation
});

self::updating(function ($model) {
// ... code here
});

self::updated(function ($model) {
// ... code here
});

self::deleting(function ($model) {
// ... code here
});

self::deleted(function ($model) {
// ... code here
});
}
Want results from more Discord servers?
Add your server