Skip to content

Conversation

@binaryfire
Copy link
Contributor

@binaryfire binaryfire commented Jan 1, 2026

Problem

The HasUuids and HasUlids traits define a public function creating() instance method to hook into the model's creating event. This prevents models from defining their own creating() method using Hyperf's instance method pattern:

class User extends Model
{
    use HasUuids;

    // ❌ PHP Fatal Error: trait method collision
    public function creating(Creating $event): void
    {
        $this->api_key = Str::random(32);
    }
}

This also causes conflicts when multiple traits try to define the same event method.

Solution

Replace the instance method with registerCallback() in a boot method:

public static function bootHasUuids(): void
{
    static::registerCallback('creating', function (self $model): void {
        // ...
    });
}

This allows:

  • Models to define their own creating() instance methods
  • Multiple traits to hook into the same event without collision
  • Consistent pattern with other Hypervel traits (Searchable, BroadcastsEvents, HasNode, etc.)

Changes

  • HasUuids: Replace creating() with bootHasUuids() using registerCallback
  • HasUlids: Replace creating() with bootHasUlids() using registerCallback

Replace instance method `creating()` with `registerCallback('creating', ...)`
to avoid method collisions when models need their own creating() hook or use
multiple traits that hook into the same event.
@albertcht albertcht added the bug Something isn't working label Jan 5, 2026
@albertcht albertcht changed the title fix(core): use registerCallback in HasUuids and HasUlids traits fix: use registerCallback in HasUuids and HasUlids traits Jan 5, 2026
@albertcht albertcht merged commit 3689cc9 into hypervel:main Jan 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants