File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -237,9 +237,16 @@ public function setAttribute($key, $value)
237
237
{
238
238
$ key = (string ) $ key ;
239
239
240
- // Add casts
241
- if ($ this ->hasCast ($ key )) {
242
- $ value = $ this ->castAttribute ($ key , $ value );
240
+ $ casts = $ this ->getCasts ();
241
+ if (array_key_exists ($ key , $ casts )) {
242
+ $ castType = $ this ->getCastType ($ key );
243
+ $ castOptions = Str::after ($ casts [$ key ], ': ' );
244
+
245
+ // Can add more native mongo type casts here.
246
+ $ value = match (true ) {
247
+ $ castType === 'decimal ' => $ this ->fromDecimal ($ value , $ castOptions ),
248
+ default => $ value ,
249
+ };
243
250
}
244
251
245
252
// Convert _id to ObjectID.
@@ -279,6 +286,19 @@ protected function asDecimal($value, $decimals)
279
286
return parent ::asDecimal ($ value , $ decimals );
280
287
}
281
288
289
+ /**
290
+ * Change to mongo native for decimal cast.
291
+ *
292
+ * @param mixed $value
293
+ * @param int $decimals
294
+ *
295
+ * @return Decimal128
296
+ */
297
+ protected function fromDecimal ($ value , $ decimals )
298
+ {
299
+ return new Decimal128 ($ this ->asDecimal ($ value , $ decimals ));
300
+ }
301
+
282
302
/** @inheritdoc */
283
303
protected function castAttribute ($ key , $ value )
284
304
{
You can’t perform that action at this time.
0 commit comments