Files
GLOC/app/Models/User.php
2026-02-07 04:52:11 +07:00

83 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use MongoDB\Laravel\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'employee_id',
'name',
'email',
'password',
'phone',
'color',
'role',
'is_active',
'agent_id', // [NEW] Link staff to agent
'user_group_id', // [NEW] Link to UserGroup (Permissions)
];
/**
* The attributes that should be hidden for serialization.
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'is_active' => 'boolean',
];
}
/**
* Get the sales routes for the user.
*/
public function salesRoutes(): HasMany
{
return $this->hasMany(SalesRoute::class);
}
/**
* Get the sales plans for the user.
*/
public function salesPlans(): HasMany
{
return $this->hasMany(SalesPlan::class);
}
/**
* Get the agent that this user belongs to.
*/
public function agent(): BelongsTo
{
return $this->belongsTo(Agent::class);
}
/**
* Get the user group (role) of the user
*/
public function group(): BelongsTo
{
return $this->belongsTo(UserGroup::class, 'user_group_id');
}
}