trypost/app/Models/Plan.php
Paulo Castellano 2da15df96c feat: introduce Account entity as billing owner and refactor architecture
- Create Account model as Cashier Billable entity (stripe, plan, subscription)
- Account owns workspaces and has an owner_id (User)
- User belongs to one Account via account_id
- Workspace belongs to Account via account_id, no longer has billing fields
- Remove Brand model entirely (workspaces serve as grouping)
- Rename brand_limit to workspace_limit in plans
- Workspace roles simplified: admin/member/viewer (owner via Account)
- Invites now belong to Account with workspaces JSON array
- Pennant features scope changed from Workspace to Account
- EnsureSubscribed middleware checks Account subscription
- All controllers updated: BillingController, OnboardingController,
  WorkspaceInviteController, SocialController, StripeEventListener
- Frontend: extract GoogleAuthButton component, create WorkspaceRole
  enum for type-safe role checks, fix all views for new architecture
- All 1101 tests passing
2026-04-14 22:22:04 -03:00

73 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\Plan\Slug;
use Database\Factories\PlanFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Plan extends Model
{
/** @use HasFactory<PlanFactory> */
use HasFactory, HasUuids;
protected $fillable = [
'slug',
'name',
'stripe_monthly_price_id',
'stripe_yearly_price_id',
'monthly_price',
'yearly_price',
'social_account_limit',
'member_limit',
'workspace_limit',
'ai_images_limit',
'ai_videos_limit',
'data_retention_days',
'sort',
'is_archived',
];
protected function casts(): array
{
return [
'slug' => Slug::class,
'is_archived' => 'boolean',
'monthly_price' => 'integer',
'yearly_price' => 'integer',
'social_account_limit' => 'integer',
'member_limit' => 'integer',
'workspace_limit' => 'integer',
'ai_images_limit' => 'integer',
'ai_videos_limit' => 'integer',
'data_retention_days' => 'integer',
'sort' => 'integer',
];
}
public function accounts(): HasMany
{
return $this->hasMany(Account::class);
}
public function scopeActive(Builder $query): Builder
{
return $query->where('is_archived', false);
}
public function formattedMonthlyPrice(): string
{
return '$'.number_format($this->monthly_price / 100, 0);
}
public function formattedYearlyPrice(): string
{
return '$'.number_format($this->yearly_price / 100, 0);
}
}