- 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
76 lines
1.6 KiB
PHP
76 lines
1.6 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',
|
|
'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->owner?->email ?? '';
|
|
}
|
|
|
|
public function stripeName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
}
|