/**
* Get the user's role
* @param string $login the login account of the user.
* @return string $role the role of the user or null when the user is not exist.
*/
public function getUserRole($login) {
$res = $this->where('login', $login)->find(1);
dump($res->role()->name);
if ($res != null && $res->role() && $res->role()->name) {
return $res->role()->name;
}
else {
return null;
}
}
/**
* Relation to role model
*/
public function role() {
return $this->belongsTo(Roles::class, 'role', 'id');
}
最佳答案