trypost/app/Models/Account.php
Paulo Castellano ded1c998ec feat: redesign billing, onboarding, sidebar, and settings architecture
- Sidebar reorganized: Workspace group (connections, hashtags, labels,
  API keys, settings) and Account group (settings, usage, billing)
- Account group only visible to owner and hidden in self-hosted mode
- Onboarding simplified: role -> account (connect socials) -> completed
  -> redirect to /subscribe. Removed Subscription setup step.
- Subscribe page redesigned with 4 plan cards, monthly/yearly toggle,
  trial info, and per-plan features list
- Billing page redesigned following Sendkit layout (sections with
  sidebar labels)
- Processing page uses usePoll with immediate watch for subscription
  activation
- Cancel URL redirects directly to /subscribe
- Account settings page with name and billing_email (syncs with Stripe)
- Usage page with ring meters for all plan limits
- Settings layout tabs only for user pages (profile, password,
  notifications). Workspace/API keys/billing are standalone pages.
- GoogleAuthButton extracted as reusable component
- WorkspaceRole TypeScript enum for type-safe role checks in frontend
- Trial period changed to 7 days
- Fixed onboarding loop when user confirms email
- All 1101 tests passing
2026-04-15 00:33:38 -03:00

77 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Database\Factories\AccountFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Laravel\Cashier\Billable;
class Account extends Model
{
/** @use HasFactory<AccountFactory> */
use Billable, HasFactory, HasUuids;
public const SUBSCRIPTION_NAME = 'default';
protected $fillable = [
'owner_id',
'name',
'billing_email',
'plan_id',
];
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'owner_id');
}
public function plan(): BelongsTo
{
return $this->belongsTo(Plan::class);
}
public function users(): HasMany
{
return $this->hasMany(User::class);
}
public function workspaces(): HasMany
{
return $this->hasMany(Workspace::class);
}
public function invites(): HasMany
{
return $this->hasMany(Invite::class);
}
public function hasActiveSubscription(): bool
{
if (config('trypost.self_hosted')) {
return true;
}
return $this->subscribed(self::SUBSCRIPTION_NAME);
}
public function isOnTrial(): bool
{
return $this->subscription(self::SUBSCRIPTION_NAME)?->onTrial() ?? false;
}
public function stripeEmail(): string
{
return $this->billing_email ?? $this->owner?->email ?? '';
}
public function stripeName(): string
{
return $this->name;
}
}