<?php

namespace Portal\Mileage\Model;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class Users extends Authenticatable
{

    use Notifiable;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';
    protected $primaryKey = 'id';
    public $timestamps = true;

    protected $fillable = [
        'name',
        'email',
        'password',
        'staff_id',
        'status',
    ];


    /**
     * undocumented function
     *
     * @return void
     * @author 
     **/
    public function info()
    {
        return $this->hasOne('Portal\Mileage\Model\VwStaff','employeeCode');
    }

    /**
     * undocumented function
     *
     * @return void
     * @author 
     **/
    public function staffInfo()
    {
        return $this->hasOne(\Portal\Mileage\Model\StaffInfo::class, 'fk_users', 'id');
    }
    

    public function projectTeams()
    {
        return $this->hasMany('Portal\Mileage\Model\ProjectTeam', 'pt_staff_id', 'employeeCode');
    }

    public function managedProjects()
    {
        return $this->projectTeams()->where('role_id', 1); // 1 = Project Manager
    }

    public function roles()
    {
        return $this->belongsToMany(\Portal\Mileage\Model\AclRole::class,
            'acl_role_user',
            'user_id',
            'role_id'
        );
    }

}
