【发布时间】:2014-07-21 15:48:05
【问题描述】:
所以在我的网站中,我正在实现一个搜索功能,用户可以在其中输入 3 个字段的值。我希望它以某种方式执行,例如,如果所有字段都有输入,它会先执行搜索,然后对第一次搜索返回的结果执行下一次搜索,最后添加最后一个搜索。我的代码如下所示:
public function search()
{
$input = Input::all();
$users = User::all();
$jobs = Job::all();
if($input->industry!=null){
$users = $users::where('industry', '==', $input->industry);
$jobs = $jobs::where('user_id', '==', $users->id);
}
if($input->location!=null){
$jobs = $jobs::where('location', '==', $input->location);
}
if($input->salary!=null){
$jobs = $jobs::where('salary', '>', $input->salary);
}
return View::make('jobs.jobsList')->with(compact('jobs'))->with(compact('users'));
}
但我在尝试获取非对象的属性时遇到错误。任何有关我如何添加此功能的提示将不胜感激。谢谢
【问题讨论】:
标签: php sql laravel model where