From 39dc3f7150ab1c7dd2e7e44fe7502c23c9d65b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 30 Nov 2021 11:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=B7=E6=A0=BC=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Casts/Price.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Casts/Price.php b/app/Casts/Price.php index 91c87fe1..adb848d8 100644 --- a/app/Casts/Price.php +++ b/app/Casts/Price.php @@ -17,6 +17,10 @@ class Price implements CastsAttributes */ public function get($model, string $key, $value, array $attributes) { + if ((string) $value === '') { + return null; + } + return bcdiv($value, 100, 2); } @@ -31,6 +35,10 @@ class Price implements CastsAttributes */ public function set($model, string $key, $value, array $attributes) { + if ((string) $value === '') { + return null; + } + return (int) bcmul($value, 100); } }