- PUT v1/client/update: gender theo enum ClientGender (0 Nam/1 Nữ), thêm
birthday (cột mới), province_code/ward_code validate theo bảng provinces/wards
(phường phải thuộc tỉnh). Migration nạp dữ liệu hành chính 2025 từ
province_ward_import.sql (chỉ bảng trống), API GET v1/provinces[/{code}/wards].
- CustomerObserver/OrderObserver log giá trị cũ bằng getRawOriginal: getOriginal
trả enum object, nối chuỗi gây 500 khi khách đổi giới tính.
- ClientResource: các cờ trả boolean, CCCD chỉ trả cccd_updated (không lộ ảnh/số).
- GET v1/setting/menu trả cả items + quick_links, bỏ v1/setting/quick-links.
- Thông báo admin/khách tra theo uuid thay vì id tự tăng.
- Chặn gửi template marketing cho khách đã tắt nhận email marketing.
- Xoá ProvinceWardSeeder và Customer::$updatable không dùng.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Customer;
|
|
use App\Repositories\Log\LogRepositoryInterface;
|
|
|
|
class CustomerObserver
|
|
{
|
|
private array $conditions = [
|
|
'password',
|
|
'remember_token',
|
|
'updated_at'
|
|
];
|
|
public function __construct(
|
|
public LogRepositoryInterface $logRepository
|
|
) {}
|
|
/**
|
|
* Handle the Customer "created" event.
|
|
*/
|
|
public function created(Customer $customer): void
|
|
{
|
|
if ($customer->id) {
|
|
$this->logRepository->create([
|
|
'agent' => request()->userAgent(),
|
|
'client_ip' => request()->getClientIp(),
|
|
'username' => auth()->guard('admin')->user()->username ?? 'System',
|
|
'description' => (auth()->guard('admin')->user()->username ?? 'System') . " created new Customer with id: " . $customer->id,
|
|
'customer_id' => $customer->id
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle the Customer "updated" event.
|
|
*/
|
|
public function updated(Customer $customer): void
|
|
{
|
|
if ($customer->getDirty()) {
|
|
foreach ($customer->getDirty() as $attribute => $value) { {
|
|
if (! in_array($attribute, $this->conditions)) {
|
|
$old_value = $customer->getRawOriginal($attribute);
|
|
$this->logRepository->create([
|
|
'agent' => request()->userAgent(),
|
|
'client_ip' => request()->getClientIp(),
|
|
'username' => auth()->guard('admin')->user()->username ?? 'System',
|
|
'description' => (auth()->guard('admin')->user()->username ?? 'System') . " Modified Customer ID#" . $customer->id . " - #$attribute from $old_value to $value",
|
|
'customer_id' => $customer->id
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle the Customer "deleted" event.
|
|
*/
|
|
public function deleted(Customer $customer): void
|
|
{
|
|
$this->logRepository->create([
|
|
'agent' => request()->userAgent(),
|
|
'client_ip' => request()->getClientIp(),
|
|
'username' => auth()->guard('admin')->user()->username ?? 'System',
|
|
'description' => (auth()->guard('admin')->user()->username ?? 'System') . " Deleted Customer ID#" . $customer->getOriginal('id'),
|
|
'customer_id' => $customer->getOriginal('id')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Handle the Customer "restored" event.
|
|
*/
|
|
public function restored(Customer $customer): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the Customer "force deleted" event.
|
|
*/
|
|
public function forceDeleted(Customer $customer): void
|
|
{
|
|
//
|
|
}
|
|
}
|