- Move billing routes from /billing to /settings/billing
- Add billing translations (en/pt-br)
- Update billing/Index.vue to use $t() for all strings
- Fix all controllers using route('dashboard') to use route('calendar') or route('accounts')
- Replace ->with('error', ...) pattern with session()->flash('flash.banner', ...)
- Add self-hosted mode support for hasActiveSubscription() and workspace methods
- Add flash translations for account connection errors
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
109 lines
2.6 KiB
PHP
109 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\User\Persona;
|
|
use App\Enums\User\Setup;
|
|
use App\Models\Traits\HasMedia;
|
|
use App\Models\Traits\HasWorkspace;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Cashier\Billable;
|
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use Billable, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'setup',
|
|
'persona',
|
|
'current_workspace_id',
|
|
'language_id',
|
|
'email_verified_at',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'two_factor_secret',
|
|
'two_factor_recovery_codes',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $appends = ['avatar'];
|
|
|
|
/**
|
|
* @return array{url: string, media_id: string|null}
|
|
*/
|
|
public function getAvatarAttribute(): array
|
|
{
|
|
$media = $this->getFirstMedia('avatar');
|
|
|
|
return [
|
|
'url' => $media?->url ?? $this->getFallbackAvatarUrl($this->name),
|
|
'media_id' => $media?->id,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
'setup' => Setup::class,
|
|
'persona' => Persona::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user's language.
|
|
*/
|
|
public function language(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Language::class);
|
|
}
|
|
|
|
/**
|
|
* Check if user has an active subscription.
|
|
* In self-hosted mode, always returns true (no subscription required).
|
|
*/
|
|
public function hasActiveSubscription(): bool
|
|
{
|
|
if (config('trypost.self_hosted')) {
|
|
return true;
|
|
}
|
|
|
|
return $this->subscribed('default');
|
|
}
|
|
|
|
/**
|
|
* Check if user has ever had a subscription (for trial eligibility).
|
|
*/
|
|
public function hasEverSubscribed(): bool
|
|
{
|
|
return $this->subscriptions()->exists();
|
|
}
|
|
}
|