我有2个表Jobs
和Departments
(一个工作属于某个部门),我想在其部门找到一些工作。
这是我必须修改的代码:
$query = Job::query()->where('status', 2);
if($input['title']!=""){
$query->where('title', 'like', '%' . $input['title'] . '%')->get();
}
if($input['location'] != ""){
$query->where('location', '=', $input['location']);
}
if($input['recruiters'] != ""){
$query->where('recruiter_id','=', $input['recruiters']);
}
$jobs = $query->paginate(5);
return $jobs;
query
变量对我没有方法join
。我试试with
但它不起作用。
join
有任何解决方案,或通过DB
进行其他查询,但并不总是设置title,location,recruiters
个变量。
抱歉我的英语不好,谢谢你的考虑。
答案 0 :(得分:0)
看看雄辩的关系:https://laravel.com/docs/5.1/eloquent-relationships#defining-relationships
您基本上在模型中定义Job和Depertment之间的关系,然后调用$job->department()->name
(这是一个示例调用)来获取所附部门的名称。