131 lines
3.1 KiB
PHP
131 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Enums\DripEmailType;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Cashier\Billable;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use Billable, HasFactory, HasUuids, Notifiable, TwoFactorAuthenticatable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'encryption_salt',
|
|
'onboarded_at',
|
|
'currency_code',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'two_factor_secret',
|
|
'two_factor_recovery_codes',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'onboarded_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function isOnboarded(): bool
|
|
{
|
|
return $this->onboarded_at !== null;
|
|
}
|
|
|
|
public function encryptedMessage(): HasOne
|
|
{
|
|
return $this->hasOne(EncryptedMessage::class);
|
|
}
|
|
|
|
public function transactions(): HasMany
|
|
{
|
|
return $this->hasMany(Transaction::class);
|
|
}
|
|
|
|
public function accounts(): HasMany
|
|
{
|
|
return $this->hasMany(Account::class);
|
|
}
|
|
|
|
public function categories(): HasMany
|
|
{
|
|
return $this->hasMany(Category::class);
|
|
}
|
|
|
|
public function banks(): HasMany
|
|
{
|
|
return $this->hasMany(Bank::class)
|
|
->where(function (Builder $query) {
|
|
$query->whereNull('user_id')
|
|
->orWhere('banks.user_id', $this->id);
|
|
});
|
|
}
|
|
|
|
public function automationRules(): HasMany
|
|
{
|
|
return $this->hasMany(AutomationRule::class);
|
|
}
|
|
|
|
public function labels(): HasMany
|
|
{
|
|
return $this->hasMany(Label::class);
|
|
}
|
|
|
|
public function mailLogs(): HasMany
|
|
{
|
|
return $this->hasMany(UserMailLog::class);
|
|
}
|
|
|
|
public function hasReceivedEmail(DripEmailType $type): bool
|
|
{
|
|
return $this->mailLogs()->where('email_type', $type)->exists();
|
|
}
|
|
|
|
public function hasProPlan(): bool
|
|
{
|
|
if (! config('subscriptions.enabled')) {
|
|
return true;
|
|
}
|
|
|
|
return $this->subscribed('default');
|
|
}
|
|
|
|
public function isDemoAccount(): bool
|
|
{
|
|
return $this->email === config('app.demo.email');
|
|
}
|
|
}
|