Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

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

By M.K. Verma · 2 May 2022

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();
        });
 }
}