gpt4 book ai didi

php - 搜索查询在 Laravel 中无法正常运行

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:10 25 4
gpt4 key购买 nike

public static function searchSubmissions($request, $candidateIds = array(),$isscontact = NULL){
$querys = DB::table('submissions')->select('submissions.*');
if ( Input::has('candidatename') and $request->input('candidatename') != NULL){
$querys->join('candidates','candidates.candidateid','=','submissions.candidateid');
$querys->where('candidates.firstname', 'LIKE', '%'. $request->input('candidatename').'%')->orWhere('candidates.lastname', 'LIKE', '%'. $request->input('candidatename') .'%')->where('submissions.status','1');
}
$result = $querys->paginate(PAGELIMIT);

return $result ;
}

This is my search query if I entered "john" or "peter" in my search field it works fine. if I entered full name "john peter" it does not work for me. In my database I have two fields 'firstname' 'lastname'

最佳答案

我认为,您需要重构代码才能使其正常工作。

$names = explode(' ', $request->input('candidatename'));

if (!empty($names)) {
foreach ($names as $name) {
$querys = $querys->orWhere('candidates.firstname', 'LIKE', '%'. $name .'%');
$querys = $querys->orWhere('candidates.lastname', 'LIKE', '%'. $name .'%');
}
}

看看这个https://laravel.com/docs/5.4/queries#parameter-grouping

关于php - 搜索查询在 Laravel 中无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48058501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com