This repository was archived by the owner on Dec 10, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,11 @@ public static function decodeUuid(string $binaryUuid): string
7171 return Uuid::fromBytes ($ binaryUuid )->toString ();
7272 }
7373
74+ public function toArray ()
75+ {
76+ return array_merge (parent ::toArray (), [$ this ->getKeyName () => $ this ->uuid_text ]);
77+ }
78+
7479 public function getUuidTextAttribute (): string
7580 {
7681 return static ::decodeUuid ($ this ->{$ this ->getKeyName ()});
Original file line number Diff line number Diff line change @@ -132,6 +132,28 @@ public function it_generates_valid_routes()
132132 $ this ->assertContains ("/uuid-test/ {$ uuid }" , route ('uuid-test ' , $ model ));
133133 }
134134
135+ /** @test */
136+ public function it_serialises_the_model_correctly ()
137+ {
138+ $ model = TestModel::create ();
139+
140+ $ json = $ model ->toJson ();
141+
142+ $ this ->assertContains ($ model ->uuid_text , $ json );
143+ $ this ->assertNotContains ($ model ->uuid , $ json );
144+ }
145+
146+ /** @test */
147+ public function it_serialises_the_model_correctly_with_json_encode ()
148+ {
149+ $ model = TestModel::create ();
150+
151+ $ json = json_encode ($ model );
152+
153+ $ this ->assertContains ($ model ->uuid_text , $ json );
154+ $ this ->assertNotContains ($ model ->uuid , $ json );
155+ }
156+
135157 private function createModel (string $ uuid , $ relationUuid = null ): TestModel
136158 {
137159 $ model = new TestModel ();
You can’t perform that action at this time.
0 commit comments