alexa

How I can generate the unique transaction ID In LARAVEL 8 ?

How I can generate the unique transaction ID In LARAVEL 8 ?

In the Transaction model class use the event created to get de ID and concatenate to transaction_id :

 class Transaction extends Model {
 ...
 public static function boot()
 {
        parent::boot();
        self::created(function ($model) { 
            $model->transaction_id = 'NMB-BOO-' . str_pad($model->id, 7, "0", STR_PAD_LEFT);
            $model->save();
        });
 }
}

561 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry