seedAdmin(); $this->seedCustomer(); } private function seedAdmin(): void { $admin = User::where('username', self::ADMIN_USERNAME)->first(); if ($admin) { $admin->update(['password' => Hash::make(self::ADMIN_PASSWORD)]); $this->command?->info('Admin đã có — đặt lại mật khẩu cho "' . self::ADMIN_USERNAME . '".'); } else { $admin = User::create([ 'fullname' => 'System Admin', 'username' => self::ADMIN_USERNAME, 'email' => 'admin@tgs.com.vn', 'email_verified_at' => now(), 'password' => Hash::make(self::ADMIN_PASSWORD), ]); $this->command?->info('Đã tạo admin "' . self::ADMIN_USERNAME . '".'); } // status nằm ngoài $fillable nên phải gán thẳng. $admin->forceFill(['status' => 1])->save(); if (method_exists($admin, 'syncRoles') && \Spatie\Permission\Models\Role::where('name', 'Full Administrator')->exists()) { $admin->syncRoles(['Full Administrator']); $this->command?->info(' → gán role Full Administrator.'); } } private function seedCustomer(): void { $customer = Customer::where('email', self::CUSTOMER_EMAIL)->first(); if ($customer) { $customer->update(['password' => Hash::make(self::CUSTOMER_PASSWORD)]); $this->command?->info('Khách hàng đã có — đặt lại mật khẩu cho ' . self::CUSTOMER_EMAIL . '.'); } else { $customer = Customer::create([ 'fullname' => 'Phạm Bảo (test)', 'username' => 'pbao.dev', 'email' => self::CUSTOMER_EMAIL, 'phone' => '0900000000', 'password' => Hash::make(self::CUSTOMER_PASSWORD), 'email_verified_at' => now(), 'email_verify' => 1, 'address' => '128/38 Tân Hương, Phú Thọ Hòa, TP. Hồ Chí Minh', ]); $this->command?->info('Đã tạo khách hàng ' . self::CUSTOMER_EMAIL . '.'); } // Nạp sẵn số dư để đặt và thanh toán đơn thử, kể cả các ca trả từng phần. $customer->forceFill([ 'status' => 1, 'total' => max((int) $customer->total, 50_000_000), ])->save(); if (empty($customer->uuid)) { $customer->forceFill(['uuid' => (string) Str::uuid()])->save(); } $this->command?->info(' → số dư: ' . number_format((int) $customer->fresh()->total) . ' VNĐ'); } }