Eloquent Laravel 5“雄辩”;加上;方法:联接多个表和联接表中的筛选列

Eloquent Laravel 5“雄辩”;加上;方法:联接多个表和联接表中的筛选列,eloquent,laravel-5,Eloquent,Laravel 5,我将用户和用户配置文件存储在两个单独的表中,其中用户表有用户名和电子邮件列,用户配置文件表有name和employee\u no列 User.php public function userProfile() { return $this->hasOne('App\Models\Utility\UserProfile', 'user_id', 'id'); } UserProfile.php public function users() { return $this-&

我将用户和用户配置文件存储在两个单独的表中,其中用户表有用户名和电子邮件列,用户配置文件表有name和employee\u no列

User.php

public function userProfile()
{
    return $this->hasOne('App\Models\Utility\UserProfile', 'user_id', 'id');
}
UserProfile.php

public function users()
{
    return $this->belongsTo('App\Models\Utility\User', 'user_id', 'id');
}
我正在使用with方法向用户加载配置文件信息。 下面的代码使用配置文件加载用户列表,并可以筛选用户名列和电子邮件列

UserManagementController.php

public function getUserProfile(){
    $users = User::with('UserProfile')
            ->where('username', 'LIKE', '%'.Input::get('q').'%')
            ->orWhere('email', 'LIKE', '%'.Input::get('q').'%')
            ->paginate(5);


    return view('user_profile',compact('users'));
}
但我无法筛选UserProfile表中的name和employee_no字段,因为我无法访问这些字段。 那么Eloquent联接多个表和联接表中的过滤列的方式是什么呢

public function getUserProfile(){
$users = User::join('UserProfile', 'users.id', '=', 'UserProfile.user_id')
        ->where('username', 'LIKE', '%'.Input::get('q').'%')
        ->orWhere('email', 'LIKE', '%'.Input::get('q').'%')
        ->orWhere('UserProfile.employee_id', 'LIKE', '%'.Input::get('q').'%')
        ->orWhere('UserProfile.name', 'LIKE', '%'.Input::get('q').'%')
        ->paginate(5);


return view('user_profile',compact('users'));
}

在Larvel查询生成器中使用连接方法解决了这个问题