From e9674d657137039ff37c209dff385bd9767b495c Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 2 Sep 2026 11:38:57 +0330 Subject: [PATCH] fix some bugs --- .../Controllers/Admin/CustomerController.php | 7 +++- app/Models/Customer.php | 12 ++++++ ...01_change_customers_birth_date_to_date.php | 41 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2026_09_02_000001_change_customers_birth_date_to_date.php diff --git a/app/Http/Controllers/Admin/CustomerController.php b/app/Http/Controllers/Admin/CustomerController.php index 244bad4..954c2c4 100644 --- a/app/Http/Controllers/Admin/CustomerController.php +++ b/app/Http/Controllers/Admin/CustomerController.php @@ -175,8 +175,11 @@ class CustomerController extends SuperController $customer = Customer::findOrFail($id); - if (array_key_exists('referral_to_id', $data) && filled($customer->referral_to_id)) { - unset($data['referral_to_id']); + if (array_key_exists('referral_to_id', $data)) { + $incoming = is_string($data['referral_to_id']) ? trim($data['referral_to_id']) : $data['referral_to_id']; + if (filled($customer->referral_to_id) || $incoming === null || $incoming === '') { + unset($data['referral_to_id']); + } } if (isset($data['fname'], $data['lname'])) { diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 0c9a06a..0b2b70c 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Hash; +use Carbon\Carbon; use Rooyesh\Wallet\models\Wallet; use Illuminate\Foundation\Auth\User as Authenticatable; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; @@ -136,6 +137,17 @@ class Customer extends Authenticatable implements JWTSubject $this->attributes['password'] = Hash::make($value); } + public function setBirthDateAttribute($value): void + { + if ($value === null || $value === '') { + $this->attributes['birth_date'] = null; + + return; + } + + $this->attributes['birth_date'] = Carbon::parse($value)->format('Y-m-d'); + } + public function getJWTIdentifier() { return $this->getKey(); diff --git a/database/migrations/2026_09_02_000001_change_customers_birth_date_to_date.php b/database/migrations/2026_09_02_000001_change_customers_birth_date_to_date.php new file mode 100644 index 0000000..2a290fa --- /dev/null +++ b/database/migrations/2026_09_02_000001_change_customers_birth_date_to_date.php @@ -0,0 +1,41 @@ +getDatabaseName(), $this->customersTable(), 'birth_date'] + ); + + $type = strtolower((string) ($row->data_type ?? '')); + if ($type === 'date') { + return; + } + + DB::statement('ALTER TABLE `'.$this->customersTable().'` MODIFY `birth_date` DATE NULL DEFAULT NULL'); + } + + public function down(): void + { + // به TIMESTAMP برنمی‌گردانیم — تاریخ‌های قبل از ۱۹۷۰ قطع می‌شوند + } + + private function customersTable(): string + { + return DB::getTablePrefix().'customers'; + } +};