*/ use HasFactory, Notifiable, TwoFactorAuthenticatable; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'two_factor_confirmed_at' => 'datetime', 'trial_ends_at' => 'datetime', ]; } protected static function booted(): void { // Every new account starts with a free trial. static::creating(function (User $user): void { $user->trial_ends_at ??= now()->addDays((int) config('plans.trial_days', 14)); }); } /** * The paid plan, if this user ever started one. * * @return HasOne */ public function subscription(): HasOne { return $this->hasOne(Subscription::class); } public function onTrial(): bool { return $this->trial_ends_at !== null && $this->trial_ends_at->isFuture(); } /** * The plan this user is on right now: the paid plan, or the free trial while it lasts, or nothing. */ public function currentPlan(): ?Plan { $subscription = $this->subscription; if ($subscription !== null && $subscription->isActive()) { return $subscription->plan; } return $this->onTrial() ? Plan::findByKey((string) config('plans.trial_plan')) : null; } /** * The stores this user owns. * * @return HasMany */ public function stores(): HasMany { return $this->hasMany(Store::class); } }