64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
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\Fortify\TwoFactorAuthenticatable;
|
|
|
|
#[Fillable(['name', 'email', 'password', 'is_admin', 'can_create_channel', 'suspended_at'])]
|
|
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable, TwoFactorAuthenticatable;
|
|
|
|
protected $attributes = [
|
|
'can_create_channel' => false,
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'is_admin' => 'boolean',
|
|
'can_create_channel' => 'boolean',
|
|
'suspended_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function channel(): HasOne
|
|
{
|
|
return $this->hasOne(Channel::class);
|
|
}
|
|
|
|
public function follows(): HasMany
|
|
{
|
|
return $this->hasMany(Follow::class);
|
|
}
|
|
|
|
public function isSuspended(): bool
|
|
{
|
|
return $this->suspended_at !== null;
|
|
}
|
|
|
|
public function canCreateChannel(): bool
|
|
{
|
|
return $this->can_create_channel || PlatformSetting::current()->channel_creation_open;
|
|
}
|
|
}
|