Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Model using the HasBinaryUuid trait is not booted correctly #39

Closed
andrzejkupczyk opened this issue Feb 28, 2018 · 3 comments
Closed

Model using the HasBinaryUuid trait is not booted correctly #39

andrzejkupczyk opened this issue Feb 28, 2018 · 3 comments
Labels

Comments

@andrzejkupczyk
Copy link

andrzejkupczyk commented Feb 28, 2018

Problem occurs when you try to convert newly created model instance to an array:

(new App\SomeModel(['foobar' => 'whatever']))->toArray();
TypeError: Argument 1 passed to App\SomeModel::decodeUuid() must be of the type string, null given, called in […]/vendor/spatie/laravel-binary-uuid/src/HasBinaryUuid.php on line 81

This happens because toArray() tries to get an "uuid text" attribute which is null at this point:

public function getUuidTextAttribute(): string
{
    return static::decodeUuid($this->{$this->getKeyName()});
}
@brendt
Copy link
Contributor

brendt commented Feb 28, 2018

Feel free to submit a PR to fix this issue!

@andrzejkupczyk
Copy link
Author

Okie dokie, it's done.

@brendt
Copy link
Contributor

brendt commented Feb 28, 2018

Thanks! We'll discuss this further in the PR

@spatie spatie locked and limited conversation to collaborators Feb 28, 2018
@brendt brendt closed this as completed Jun 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants