faker = \Faker\Factory::create(); parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $path = $this->option('path') ?? storage_path('migrations/import'); $directory = new \DirectoryIterator($path); foreach ($directory as $file) { if ($file->getExtension() === 'zip') { $this->info('Started processing: '.$file->getBasename().' at '.now()); StartMigration::dispatch($file->getRealPath(), $this->getUser(), $this->getUser()->companies()->first()); } } } public function getUser(): User { $account = $this->getAccount(); $company = $this->getCompany($account); $user = User::factory()->create([ 'account_id' => $account->id, 'email' => $this->faker->email, 'confirmation_code' => $this->createDbHash(config('database.default')), ]); $company_token = CompanyToken::create([ 'user_id' => $user->id, 'company_id' => $company->id, 'account_id' => $account->id, 'name' => 'test token', 'token' => \Illuminate\Support\Str::random(64), ]); $user->companies()->attach($company->id, [ 'account_id' => $account->id, 'is_owner' => 1, 'is_admin' => 1, 'is_locked' => 0, 'notifications' => CompanySettings::notificationDefaults(), 'permissions' => '', 'settings' => null, ]); return $user; } public function getAccount(): Account { return Account::factory()->create(); } public function getCompany(Account $account): Company { $company = Company::factory()->create([ 'account_id' => $account->id, ]); if (! $account->default_company_id) { $account->default_company_id = $company->id; $account->save(); } return $company; } }