<?php

namespace Portal\Mileage\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Users extends Model
{

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


    /**
     * 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->belongsTo('Portal\Mileage\Model\StaffInfo','id','fk_users');
    }

    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'
        );
    }

}
