From e1ffbf52fe28cc36614e2ffb191500d276c7d31c Mon Sep 17 00:00:00 2001 From: baodev0 Date: Tue, 27 Oct 2026 08:37:57 +0700 Subject: [PATCH] =?UTF-8?q?fix(customer):=20l=C6=B0u=20v=C3=A0=20tr?= =?UTF-8?q?=E1=BA=A3=20=C4=91=E1=BB=8Ba=20ch=E1=BB=89=20kh=C3=A1ch=20h?= =?UTF-8?q?=C3=A0ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bảng customers chỉ có cột address nên address_1/address_2 từ form admin bị bỏ khi validate. Thêm cột address_2, fillable, rule validate và trả đủ field địa chỉ trong CustomerResource. Co-Authored-By: Claude Sonnet 5.5 --- app/Http/Requests/CreateCustomerRequest.php | 3 ++- .../Resources/Api/Admin/CustomerResource.php | 6 +++++ app/Models/Customer.php | 1 + ...00001_add_address_2_to_customers_table.php | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2026_10_27_000001_add_address_2_to_customers_table.php diff --git a/app/Http/Requests/CreateCustomerRequest.php b/app/Http/Requests/CreateCustomerRequest.php index 11d334a..fa3c560 100644 --- a/app/Http/Requests/CreateCustomerRequest.php +++ b/app/Http/Requests/CreateCustomerRequest.php @@ -28,7 +28,8 @@ class CreateCustomerRequest extends FormRequest 'status' => 'nullable|integer|in:0,1,2,3', 'company' => 'nullable', 'phone' => 'nullable', - 'address' => 'nullable', + 'address' => 'nullable|string|max:255', + 'address_2' => 'nullable|string|max:255', 'city' => 'nullable', 'state' => 'nullable', 'postcode' => 'nullable', diff --git a/app/Http/Resources/Api/Admin/CustomerResource.php b/app/Http/Resources/Api/Admin/CustomerResource.php index 6cf5c77..cfaf339 100644 --- a/app/Http/Resources/Api/Admin/CustomerResource.php +++ b/app/Http/Resources/Api/Admin/CustomerResource.php @@ -16,6 +16,12 @@ class CustomerResource extends JsonResource 'email' => $this->email, 'phone' => $this->phone, 'company' => $this->company, + 'address' => $this->address, + 'address_2' => $this->address_2, + 'city' => $this->city, + 'state' => $this->state, + 'postcode' => $this->postcode === null ? null : (string) $this->postcode, + 'country' => $this->country, 'note' => $this->note, 'status' => (int) $this->status, 'total' => (int) $this->total, diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 5fd3abc..5415133 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -52,6 +52,7 @@ class Customer extends Authenticatable implements JWTSubject 'username', 'avatar', 'address', + 'address_2', 'state', 'city', 'postcode', diff --git a/database/migrations/2026_10_27_000001_add_address_2_to_customers_table.php b/database/migrations/2026_10_27_000001_add_address_2_to_customers_table.php new file mode 100644 index 0000000..bc2bc72 --- /dev/null +++ b/database/migrations/2026_10_27_000001_add_address_2_to_customers_table.php @@ -0,0 +1,24 @@ +string('address', 255)->nullable()->change(); + $table->string('address_2', 255)->nullable()->after('address'); + }); + } + + public function down(): void + { + Schema::table('customers', function (Blueprint $table) { + $table->dropColumn('address_2'); + $table->string('address', 100)->nullable()->change(); + }); + } +};