96 خطوط
2.4 KiB
PHP
96 خطوط
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Modules\Identity\Domain\Enums\AccountStatus;
|
|
use App\Modules\Identity\Domain\Enums\UserRole;
|
|
use App\Modules\Organizations\Domain\Organization;
|
|
use App\Modules\Teams\Domain\Team;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasApiTokens, HasFactory, HasUlids, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'organization_id',
|
|
'name',
|
|
'first_name',
|
|
'last_name',
|
|
'department',
|
|
'job_level',
|
|
'direct_manager_id',
|
|
'email',
|
|
'password',
|
|
'role',
|
|
'status',
|
|
'locale',
|
|
'timezone',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'role' => UserRole::class,
|
|
'status' => AccountStatus::class,
|
|
];
|
|
}
|
|
|
|
public function organization(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organization::class);
|
|
}
|
|
|
|
public function teams(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Team::class, 'team_memberships')->withTimestamps();
|
|
}
|
|
|
|
public function managedTeams(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Team::class, 'team_managers')->withTimestamps();
|
|
}
|
|
|
|
public function directManager(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'direct_manager_id');
|
|
}
|
|
|
|
public function directReports(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'direct_manager_id');
|
|
}
|
|
}
|