我正在使用 laravel 6.10 版本,因为我正在实现搜索,
我有 3 张桌子
1) course_category
2) course_sub_category
3) 课程 [course_id_category(外键),course_sub_category_id(外键)]
下面是我的代码
$course = $request->searchItem;
if ($course=="") {
$Courses = DB::table('course')
->join('course_category', 'course.course_category_id', '=', 'course_category.id')
->select('course.*','course_category.title as category_title','course_category.thumb as category_thumb')
->orderBy('course.title','asc')
->paginate(15);
}
else{
$Courses = DB::table('course')
->join('course_category', 'course.course_category_id', '=', 'course_category.id')
->join('course_sub_category', 'course.course_sub_category_id', '=', 'course_sub_category.id')
->select('course.*','course_category.title as category_title','course_category.thumb as category_thumb')
->where('course.title', 'LIKE', '%'.$course.'%')
->orWhere('course_category.title', 'LIKE', '%'.$course.'%')
->orWhere('course_sub_category.title', 'LIKE', '%'.$course.'%')
->get();
}
当我返回值时,我正在获取 0 个数组,但是当我从现有的查询中删除一个或位置时,我的查询正在工作并且它的返回值我们所有的值都匹配
意味着当我在 laravel 中使用多个 orWhere 时,我的 where 不起作用,请分享相同的解决方案。
狐的传说