src/UuidModelTrait.php
/**
     * Boot the trait, adding a creating observer.
     *
     * When persisting a new model instance, we resolve the UUID field, then set
     * a fresh UUID, taking into account if we need to cast to binary or not.
     *
     * @return void
     */
Boot the trait, adding a creating observer.
When persisting a new model instance, we resolve the UUID field, then set
a fresh UUID, taking into account if we need to cast to binary or not.

@return void
Boot the trait adding a creating observer . When persisting a new model instance we resolve the UUID field then set a fresh UUID taking into account if we need to cast to binary or not . @return void
protected static function bootUuidModelTrait(): void
    {
        static::creating(static function (Model $model) {
            $model->incrementing = false;
            $model->addUuidCast();
            $uuid = $model->resolveUuid();
            $key = $model->getKeyName();
            if (isset($model->attributes[$key]) && $model->attributes[$key] !== null) {
                $uuid = Uuid::fromString(strtolower($model->attributes[$key]));
            }
            $model->attributes[$key] = $model->hasCast($key, 'uuid') ? $uuid->getBytes() : $uuid->toString();
        });
        static::retrieved(static function ($model) {
            $model->incrementing = false;
            $model->addUuidCast();
        });
    }
protected static function bootUuidModelTrait ( ) : void { static :: creating ( static function ( Model $ model ) { $ model -> incrementing = false ; $ model -> addUuidCast ( ) ; $ uuid = $ model -> resolveUuid ( ) ; $ key = $ model -> getKeyName ( ) ; if ( isset ( $ model -> attributes [ $ key ] ) && $ model -> attributes [ $ key ] !== null ) { $ uuid = Uuid :: fromString ( strtolower ( $ model -> attributes [ $ key ] ) ) ; } $ model -> attributes [ $ key ] = $ model -> hasCast ( $ key , 'uuid' ) ? $ uuid -> getBytes ( ) : $ uuid -> toString ( ) ; } ) ; static :: retrieved ( static function ( $ model ) { $ model -> incrementing = false ; $ model -> addUuidCast ( ) ; } ) ; }
Boot the trait, adding a creating observer.
Boot the trait adding a creating observer .
/* @var Model|static $model */