@@ -61,13 +61,15 @@ public static function bootBinaryUuidSupportableTrait(): void
61
61
{
62
62
static ::creating (
63
63
function (Model $ model ) {
64
+ $ uuid = $ model ->getKeyName ();
65
+
64
66
/** @var Model|BinaryUuidSupportableTrait $model */
65
- if (!isset ($ model ->attributes [' uuid ' ])) {
66
- $ model ->uuid = $ model ->generateUuid ();
67
- } elseif (Uuid::isValid ($ model ->attributes [' uuid ' ])) {
68
- $ model ->uuid = Uuid::fromString ($ model ->attributes [' uuid ' ])->getBytes ();
69
- } elseif (is_string ($ model ->attributes [' uuid ' ]) && strlen ($ model ->attributes [' uuid ' ]) === 16 ) {
70
- $ model ->uuid = $ model ->attributes [' uuid ' ];
67
+ if (!isset ($ model ->attributes [$ uuid ])) {
68
+ $ model ->$ uuid = $ model ->generateUuid ();
69
+ } elseif (Uuid::isValid ($ model ->attributes [$ uuid ])) {
70
+ $ model ->$ uuid = Uuid::fromString ($ model ->attributes [$ uuid ])->getBytes ();
71
+ } elseif (is_string ($ model ->attributes [$ uuid ]) && strlen ($ model ->attributes [$ uuid ]) === 16 ) {
72
+ $ model ->$ uuid = $ model ->attributes [$ uuid ];
71
73
}
72
74
73
75
if (isset ($ model ->readable ) && $ model ->readable ) {
@@ -101,13 +103,15 @@ public function generateUuid(): string
101
103
*/
102
104
public function uuid (): string
103
105
{
104
- if (!isset ($ this ->uuid )) {
106
+ $ uuid = $ this ->getKeyName ();
107
+
108
+ if (!isset ($ this ->$ uuid )) {
105
109
throw new AccessedUnsetUuidPropertyException (
106
110
'Cannot get UUID property for not saved model '
107
111
);
108
112
}
109
113
110
- return Uuid::fromBytes ($ this ->uuid )->toString ();
114
+ return Uuid::fromBytes ($ this ->$ uuid )->toString ();
111
115
}
112
116
113
117
/**
@@ -119,6 +123,8 @@ public function uuid(): string
119
123
*/
120
124
public static function find (string $ uuid ): Model
121
125
{
122
- return static ::where ('uuid ' , '= ' , Uuid::fromString ($ uuid )->getBytes ())->firstOrFail ();
126
+ $ uuidKey = app (static ::class)->getKeyName ();
127
+
128
+ return static ::where ($ uuidKey , '= ' , Uuid::fromString ($ uuid )->getBytes ())->firstOrFail ();
123
129
}
124
130
}
0 commit comments