This repository was archived by the owner on Dec 10, 2018. It is now read-only.
File tree 4 files changed +19
-3
lines changed
4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
language : php
2
2
3
3
php :
4
- - 7.0
5
4
- 7.1
6
5
- 7.2
7
6
Original file line number Diff line number Diff line change 16
16
}
17
17
],
18
18
"require" : {
19
- "php" : " ^7.0 " ,
19
+ "php" : " ^7.1 " ,
20
20
"illuminate/queue" : " ~5.5.28|~5.6.0" ,
21
21
"ramsey/uuid" : " ^3.7"
22
22
},
Original file line number Diff line number Diff line change @@ -73,11 +73,19 @@ public static function decodeUuid(string $binaryUuid): string
73
73
74
74
public function toArray ()
75
75
{
76
+ if (! $ this ->exists ) {
77
+ return parent ::toArray ();
78
+ }
79
+
76
80
return array_merge (parent ::toArray (), [$ this ->getKeyName () => $ this ->uuid_text ]);
77
81
}
78
82
79
- public function getUuidTextAttribute (): string
83
+ public function getUuidTextAttribute (): ? string
80
84
{
85
+ if (! $ this ->exists ) {
86
+ return null ;
87
+ }
88
+
81
89
return static ::decodeUuid ($ this ->{$ this ->getKeyName ()});
82
90
}
83
91
Original file line number Diff line number Diff line change @@ -155,4 +155,13 @@ public function it_serialises_the_model_correctly_with_json_encode()
155
155
$ this ->assertContains ($ model ->uuid_text , $ json );
156
156
$ this ->assertNotContains ($ model ->uuid , $ json );
157
157
}
158
+
159
+ /** @test */
160
+ public function it_prevents_decoding_the_uuid_when_the_model_does_not_exist ()
161
+ {
162
+ $ model = new TestModel ;
163
+
164
+ $ this ->assertEmpty ($ model ->toArray ());
165
+ $ this ->assertNull ($ model ->uuid_text );
166
+ }
158
167
}
You can’t perform that action at this time.
0 commit comments