我试图用分页法在Eloquent中表达MySQL语句
代码:
$query = "(SELECT city_name FROM Cities WHERE city_name LIKE '%" .
$keyword . "%')
UNION
(SELECT area_name FROM Areas WHERE area_name LIKE '%" .
$keyword . "%')
UNION
(SELECT sub_location_name FROM Sub_locations WHERE sub_location_name LIKE '%" .
$keyword . "%' )";
答案 0 :(得分:0)
试试这个:
$cities = DB::table('Cities')->select('city_name')->where('city_name', $keyword);
$area=DB::table('Areas')->select('area_name')->where('area_name', $keyword);
$result=DB::table('Sub_locations')
->select('sub_location_name')
->where('sub_location_name', $keyword)
->union($cities)
->union($area)
->paginate(15);