first&last
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens;
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'role',
|
||||
'phone',
|
||||
'avatar',
|
||||
'department_id',
|
||||
'is_active',
|
||||
'last_login_at',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'last_login_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
'role' => UserRole::class,
|
||||
];
|
||||
|
||||
public function department(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class);
|
||||
}
|
||||
|
||||
public function clientRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServiceRequest::class, 'client_id');
|
||||
}
|
||||
|
||||
public function assignedRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServiceRequest::class, 'assigned_to');
|
||||
}
|
||||
|
||||
public function requestComments(): HasMany
|
||||
{
|
||||
return $this->hasMany(RequestComment::class);
|
||||
}
|
||||
|
||||
public function requestAttachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(RequestAttachment::class);
|
||||
}
|
||||
|
||||
public function activityLogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ActivityLog::class);
|
||||
}
|
||||
|
||||
public function equipment(): HasMany
|
||||
{
|
||||
return $this->hasMany(Equipment::class, 'client_id');
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->role === UserRole::ADMIN;
|
||||
}
|
||||
|
||||
public function isManager(): bool
|
||||
{
|
||||
return $this->role === UserRole::MANAGER;
|
||||
}
|
||||
|
||||
public function isTechnician(): bool
|
||||
{
|
||||
return $this->role === UserRole::TECHNICIAN;
|
||||
}
|
||||
|
||||
public function isClient(): bool
|
||||
{
|
||||
return $this->role === UserRole::CLIENT;
|
||||
}
|
||||
|
||||
public function isStaff(): bool
|
||||
{
|
||||
return $this->isAdmin() || $this->isManager() || $this->isTechnician();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user