From 29e14a4fde4e2c6611567a9faa8f1b394f3a4c69 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 13 Aug 2021 16:13:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9setPasswordAttribute=E7=9A=84?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Agent.php | 14 +++++++------- app/Models/Supplier.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Models/Agent.php b/app/Models/Agent.php index 74af22c..02207b1 100644 --- a/app/Models/Agent.php +++ b/app/Models/Agent.php @@ -33,13 +33,13 @@ class Agent extends BaseModel public function setPasswordAttribute($value) { - //新增时 - if ($value && empty($this->attributes['password'])) { - $this->attributes['password'] = $this->passMd5($value); - } - //编辑时 - else if ($value && !empty($this->attributes['password']) && $this->attributes['password'] != $value) { - $this->attributes['password'] = $this->passMd5($value); + if ($value) { + if ( + empty($this->attributes['password']) || //新增时 + $this->attributes['password'] != $value && !empty($this->attributes['password']) //编辑时 + ) { + $this->attributes['password'] = $this->passMd5($value); + } } } diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index c31015c..73faf15 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -21,13 +21,13 @@ class Supplier extends BaseModel public function setPasswordAttribute($value) { - //新增时 - if ($value && empty($this->attributes['password'])) { - $this->attributes['password'] = $this->passMd5($value); - } - //编辑时 - else if ($value && !empty($this->attributes['password']) && $this->attributes['password'] != $value) { - $this->attributes['password'] = $this->passMd5($value); + if ($value) { + if ( + empty($this->attributes['password']) || //新增时 + $this->attributes['password'] != $value && !empty($this->attributes['password']) //编辑时 + ) { + $this->attributes['password'] = $this->passMd5($value); + } } } }