<?phpnamespaceApp\Traits;useIlluminate\Support\Str;useRamsey\Uuid\Exception\UnsatisfiedDependencyException;traitUuid{protectedstaticfunctionboot(){parent::boot();static::creating(function($model){try{$model->id=(string)Str::uuid();// generate uuid// Change id with your primary key}catch(UnsatisfiedDependencyException$e){abort(500,$e->getMessage());}});}}