trypost/app/Models/User.php

112 lines
2.6 KiB
PHP
Raw Normal View History

2026-01-15 01:13:44 +00:00
<?php
declare(strict_types=1);
2026-01-15 01:13:44 +00:00
namespace App\Models;
use App\Enums\User\Persona;
use App\Enums\User\Setup;
use App\Models\Traits\HasMedia;
2026-01-19 00:49:13 +00:00
use App\Models\Traits\HasWorkspace;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
2026-01-15 01:13:44 +00:00
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
2026-01-15 01:13:44 +00:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Cashier\Billable;
class User extends Authenticatable implements MustVerifyEmail
2026-01-15 01:13:44 +00:00
{
/** @use HasFactory<UserFactory> */
2026-01-20 19:53:54 +00:00
use Billable, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable;
2026-01-15 01:13:44 +00:00
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'setup',
'persona',
'current_workspace_id',
2026-01-20 19:53:54 +00:00
'email_verified_at',
2026-01-15 01:13:44 +00:00
];
/**
* 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 = [
'has_photo',
'photo_url',
];
public function getHasPhotoAttribute(): bool
{
return $this->getFirstMedia('avatar') !== null;
}
public function getPhotoUrlAttribute(): ?string
{
return $this->getFirstMediaUrl('avatar');
}
2026-01-15 01:13:44 +00:00
/**
* 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,
2026-01-15 01:13:44 +00:00
];
}
/**
* @return HasMany<Notification, $this>
*/
public function notifications(): HasMany
{
return $this->hasMany(Notification::class);
}
2026-01-15 01:13:44 +00:00
/**
* Check if user has an active subscription.
* In self-hosted mode, always returns true (no subscription required).
2026-01-15 01:13:44 +00:00
*/
public function hasActiveSubscription(): bool
{
if (config('trypost.self_hosted')) {
return true;
}
2026-01-15 01:13:44 +00:00
return $this->subscribed('default');
}
/**
* Check if user has ever had a subscription (for trial eligibility).
*/
public function hasEverSubscribed(): bool
{
return $this->subscriptions()->exists();
}
2026-01-15 01:13:44 +00:00
}