Files
mytodos/app/Models/Plan.php
T

92 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\WorkspaceType;
use Database\Factories\PlanFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
/**
* A plan is a tier of access: it decides what kind of workspace a subscriber
* gets, how many members it may hold, and how many folders and notes its
* members may create. Every plan is editable by a site administrator, so the
* limits live in the database rather than in configuration.
*
* @property int $id
* @property string $key
* @property string $name
* @property WorkspaceType $workspace_type
* @property string|null $stripe_price
* @property string $interval
* @property int $amount
* @property int|null $seat_limit
* @property int|null $max_folders
* @property int|null $max_folder_depth
* @property int|null $max_notes_per_folder
* @property int|null $note_chars
* @property int $sort_order
* @property bool $is_active
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
#[Fillable([
'key',
'name',
'workspace_type',
'stripe_price',
'interval',
'amount',
'seat_limit',
'max_folders',
'max_folder_depth',
'max_notes_per_folder',
'note_chars',
'sort_order',
'is_active',
])]
class Plan extends Model
{
/** @use HasFactory<PlanFactory> */
use HasFactory;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'workspace_type' => WorkspaceType::class,
'amount' => 'integer',
'seat_limit' => 'integer',
'max_folders' => 'integer',
'max_folder_depth' => 'integer',
'max_notes_per_folder' => 'integer',
'note_chars' => 'integer',
'sort_order' => 'integer',
'is_active' => 'boolean',
];
}
/**
* @return HasMany<Organization, $this>
*/
public function organizations(): HasMany
{
return $this->hasMany(Organization::class);
}
/**
* Determine whether the plan can be sold, that is, it has a Stripe price.
*/
public function isPurchasable(): bool
{
return is_string($this->stripe_price) && $this->stripe_price !== '';
}
}