-
Notifications
You must be signed in to change notification settings - Fork 58
Conversation
Seems nice, your thoughts @brendt ? @faustbrian could you also update the readme, mentioning the new behaviour? |
Added it to the human-readable section. |
@faustbrian Thanks! Could you also add a test to prove that it works? |
The workaround @faustbrian works but it hard-codes the We could add a separate trait which takes care of this, but I'd also like to suggest another solution, by adding the following to the public function toArray()
{
return array_merge(parent::toArray(), [$this->getKeyName() => $this->uuid_text]);
} This solution doesn't require overriding multiple methods, and doesn't depend on a hard-coded name for the id attribute. I've pushed a branch containing this solution here: https://github.com/spatie/laravel-binary-uuid/tree/json_encode-support But I'd like to hear your thoughts first. @faustbrian am I correct that the above snippet also fixes your use case? What's your opinion on the two solutions? |
I purposely put it on the Looks good to me that solution, will just add my |
I actually also see a use for the @freekmurze Ok for you if we add both? I would put the |
The
Not a fan of having yet another trait. The trait wouldn't be correct when the key name isn't |
Ok, see #18. I'll be closing this PR then. |
This allows to continue to use the
id
attribute as usually but will return theuuid_text
attribute.$user->id
will be the same as$user->uuid_text