File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,13 @@ public function toArray()
7777 return parent ::toArray ();
7878 }
7979
80- return array_merge (parent ::toArray (), [$ this ->getKeyName () => $ this ->uuid_text ]);
80+ $ data = parent ::toArray ();
81+
82+ if (isset ($ data [$ this ->getKeyName ()])) {
83+ $ data [$ this ->getKeyName ()] = $ this ->uuid_text ;
84+ }
85+
86+ return $ data ;
8187 }
8288
8389 public function getUuidTextAttribute (): ?string
Original file line number Diff line number Diff line change @@ -164,4 +164,14 @@ public function it_prevents_decoding_the_uuid_when_the_model_does_not_exist()
164164 $ this ->assertEmpty ($ model ->toArray ());
165165 $ this ->assertNull ($ model ->uuid_text );
166166 }
167+
168+ /** @test */
169+ public function it_prevents_decoding_model_key_when_it_is_not_included_in_attributes ()
170+ {
171+ $ model = TestModel::create ();
172+ $ model ->setRawAttributes (['test ' => 'test ' ]);
173+ $ array = $ model ->toArray ();
174+
175+ $ this ->assertFalse (isset ($ array [$ model ->getKeyName ()]));
176+ }
167177}
You can’t perform that action at this time.
0 commit comments