option('email'); $password = (string) $this->option('password'); $tenantName = (string) $this->option('tenant'); $userName = (string) $this->option('name'); $firstName = (string) $this->option('first_name'); $lastName = (string) $this->option('last_name'); $address = (string) $this->option('address'); $phone = (string) $this->option('phone'); $this->info('Starting dummy tenant creation with email: ' . $email); // Pre-flight checks for common failures if (! Schema::hasTable('users')) { $this->error("Table 'users' does not exist. Run: php artisan migrate"); return self::FAILURE; } if (! Schema::hasTable('tenants')) { $this->error("Table 'tenants' does not exist. Run: php artisan migrate"); return self::FAILURE; } DB::beginTransaction(); try { // Create or fetch tenant $slug = Str::slug($tenantName ?: 'demo-tenant'); /** @var Tenant $tenant */ $tenant = Tenant::query()->where('slug', $slug)->first(); if (! $tenant) { $tenant = new Tenant(); $tenant->name = $tenantName; $tenant->slug = $slug; $tenant->domain = null; $tenant->contact_name = $userName; $tenant->contact_email = $email; $tenant->contact_phone = $phone ?: null; $tenant->event_credits_balance = 1; $tenant->max_photos_per_event = 500; $tenant->max_storage_mb = 1024; $tenant->features = ['custom_branding' => false]; $tenant->is_active = true; $tenant->is_suspended = false; $tenant->save(); $this->info('Created new tenant: ' . $tenant->name); } else { $this->info('Using existing tenant: ' . $tenant->name); } // Create or fetch user /** @var User $user */ $user = User::query()->where('email', $email)->first(); $updatePassword = (bool) $this->option('update-password'); if (! $user) { $user = new User(); if (Schema::hasColumn($user->getTable(), 'name')) $user->name = $userName; $user->email = $email; $user->password = Hash::make($password); $this->info('Creating new user: ' . $email); } else if ($updatePassword) { $user->password = Hash::make($password); $this->info('Updating password for existing user: ' . $email); } if (Schema::hasColumn($user->getTable(), 'first_name')) $user->first_name = $firstName; if (Schema::hasColumn($user->getTable(), 'last_name')) $user->last_name = $lastName; if (Schema::hasColumn($user->getTable(), 'address')) $user->address = $address; if (Schema::hasColumn($user->getTable(), 'phone')) $user->phone = $phone; if (Schema::hasColumn($user->getTable(), 'tenant_id')) { $user->tenant_id = $tenant->id; } if (Schema::hasColumn($user->getTable(), 'role')) { $user->role = 'tenant_admin'; } $user->save(); $this->info('User saved successfully.'); DB::commit(); } catch (\Throwable $e) { DB::rollBack(); $this->error('Failed: '.$e->getMessage()); $this->error('Stack trace: ' . $e->getTraceAsString()); return self::FAILURE; } $this->info('Dummy tenant user created/updated.'); $this->line('Tenant: '.$tenant->name.' (#'.$tenant->id.')'); $this->line('Email: '.$email); $this->line('Password: '.$password); return self::SUCCESS; } }