File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ protected function decodeVirtualColumn(): void
4545 foreach ($ this ->getAttribute (static ::getDataColumn ()) ?? [] as $ key => $ value ) {
4646 $ attributeHasEncryptedCastable = in_array (data_get ($ this ->getCasts (), $ key ), $ encryptedCastables );
4747
48- if ($ attributeHasEncryptedCastable && $ this ->valueEncrypted ($ value )) {
48+ if ($ value && $ attributeHasEncryptedCastable && $ this ->valueEncrypted ($ value )) {
4949 $ this ->attributes [$ key ] = $ value ;
5050 } else {
5151 $ this ->setAttribute ($ key , $ value );
Original file line number Diff line number Diff line change @@ -143,13 +143,16 @@ public function encrypted_casts_work_with_virtual_column() {
143143 'json ' => json_encode (['foo ' , 'bar ' ]), // 'encrypted:json'
144144 'object ' => (object ) json_encode (['foo ' , 'bar ' ]), // 'encrypted:object'
145145 'custom ' => 'foo ' , // Custom castable β 'EncryptedCast::class'
146+ 'null_value ' => null , // 'encrypted'
146147 ]);
147148
148149 foreach ($ encryptedAttributes as $ key => $ expectedValue ) {
149150 $ savedValue = $ model ->getAttributes ()[$ key ]; // Encrypted
150151
151- $ this ->assertTrue ($ model ->valueEncrypted ($ savedValue ));
152- $ this ->assertNotEquals ($ expectedValue , $ savedValue );
152+ if ($ savedValue !== null ) {
153+ $ this ->assertTrue ($ model ->valueEncrypted ($ savedValue ));
154+ $ this ->assertNotEquals ($ expectedValue , $ savedValue );
155+ }
153156
154157 $ retrievedValue = $ model ->$ key ; // Decrypted
155158
@@ -178,6 +181,7 @@ class MyModel extends ParentModel
178181 'json ' => 'encrypted:json ' ,
179182 'object ' => 'encrypted:object ' ,
180183 'custom ' => EncryptedCast::class,
184+ 'null_value ' => 'encrypted ' ,
181185 ];
182186}
183187
You canβt perform that action at this time.
0 commit comments