trypost/app/Actions/Workspace/DeleteWorkspace.php
Paulo Castellano aacc4390a2 refactor(billing): replace MonthlyCreditsLimit Pennant feature with BillingCycle
Credit allotment is now derived directly from BillingCycle::for($account)->creditAllotment()
instead of a cached Pennant feature, removing the dynamic cache-invalidation footgun
(forgetPlanFeatureCache) that had to be called from every subscription/workspace mutation.
2026-06-22 09:55:03 -03:00

29 lines
686 B
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Workspace;
use App\Jobs\PostHog\SyncAccountUsage;
use App\Models\User;
use App\Models\Workspace;
use App\Services\PostHogService;
class DeleteWorkspace
{
public static function execute(User $user, Workspace $workspace): void
{
User::where('current_workspace_id', $workspace->id)->update(['current_workspace_id' => null]);
$account = $workspace->account;
$accountId = (string) $workspace->account_id;
$workspace->delete();
$account?->syncWorkspaceQuantity();
if (PostHogService::isEnabled()) {
SyncAccountUsage::dispatch($accountId, null);
}
}
}