truncate(); DB::table('user_vips')->truncate(); DB::table('socialite_users')->truncate(); DB::table('personal_access_tokens')->truncate(); DB::table('wallets')->truncate(); DB::table('wallet_logs')->truncate(); DB::table('wallet_to_bank_logs')->truncate(); DB::table('balances')->truncate(); DB::table('users')->truncate(); $this->faker = $this->withFaker(); $this->createUsers(1); } protected function createUsers($vip, $parent = null) { if ($vip > 7) { return; } $faker = $this->faker; for ($i = 0; $i < $faker->numberBetween(1, 5); $i++) { $user = $this->createUser($vip, $parent); $this->createUsers($vip + 1, $user); } } protected function createUser($vip = null, $inviter = null) { $faker = $this->faker; $time = now(); $phone = $this->fakePhone(); $email = $this->fakeEmail(); $user = User::create([ 'phone' => $phone, 'phone_verified_at' => $time, 'email' => $email, 'email_verified_at' => $time, 'register_ip' => $faker->ipv4, 'status' => 1, 'agent_id' => ($vip && $vip <= 6) ? $vip : null ], $inviter); return $user; } protected function fakePhone() { do { $phone = substr($this->faker->e164PhoneNumber, 1); } while(User::where('phone', $phone)->exists()); return $phone; } protected function fakeEmail() { do { $email = $this->faker->email; } while(User::where('email', $email)->exists()); return $email; } protected function withFaker() { return Container::getInstance()->make(Generator::class); } }