@@ -61,13 +61,15 @@ public static function bootBinaryUuidSupportableTrait(): void
6161 {
6262 static ::creating (
6363 function (Model $ model ) {
64+ $ uuid = $ model ->getKeyName ();
65+
6466 /** @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 ];
7173 }
7274
7375 if (isset ($ model ->readable ) && $ model ->readable ) {
@@ -101,13 +103,15 @@ public function generateUuid(): string
101103 */
102104 public function uuid (): string
103105 {
104- if (!isset ($ this ->uuid )) {
106+ $ uuid = $ this ->getKeyName ();
107+
108+ if (!isset ($ this ->$ uuid )) {
105109 throw new AccessedUnsetUuidPropertyException (
106110 'Cannot get UUID property for not saved model '
107111 );
108112 }
109113
110- return Uuid::fromBytes ($ this ->uuid )->toString ();
114+ return Uuid::fromBytes ($ this ->$ uuid )->toString ();
111115 }
112116
113117 /**
@@ -119,6 +123,8 @@ public function uuid(): string
119123 */
120124 public static function find (string $ uuid ): Model
121125 {
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 ();
123129 }
124130}
0 commit comments