73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory, Notifiable, HasRoles, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'locale',
|
|
'preferred_calendar',
|
|
'is_active',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
public function tenant()
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function managedProjects()
|
|
{
|
|
return $this->hasMany(Project::class, 'manager_id');
|
|
}
|
|
|
|
public function projects()
|
|
{
|
|
return $this->belongsToMany(Project::class, 'project_users')
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function assignedTasks()
|
|
{
|
|
return $this->hasMany(Task::class, 'assignee_id');
|
|
}
|
|
|
|
public function getLocale(): string
|
|
{
|
|
return $this->locale ?? $this->tenant?->default_locale ?? config('Vernova.default_locale', 'fa');
|
|
}
|
|
|
|
public function getCalendar(): string
|
|
{
|
|
return $this->preferred_calendar ?? $this->tenant?->default_calendar ?? config('Vernova.default_calendar', 'jalali');
|
|
}
|
|
|
|
public function getDirection(): string
|
|
{
|
|
return in_array($this->getLocale(), config('Vernova.rtl_locales', [])) ? 'rtl' : 'ltr';
|
|
}
|
|
}
|