我是使用查询生成器的新手,今天我停留在查询生成器上。我试图做名称列也要多选。这是我要转换查询生成器的内容:
SELECT
users.name,
users.surname,
users.avatar_path,
users.city_id,
users.district_id,
users.neighboor_id,
cities.name as city_name
FROM users,cities
WHERE users.city_id = cities.id
AND users.name LIKE 'bar%'
没有使用 DB :: raw()吗?
谢谢。
答案 0 :(得分:1)
在此处使用join query
DB::table('users')
->select('users.name','users.surname','users.avatar_path','users.city_id','users.district_id','users.neighboor_id','cities.name as city_name')
->join('users','users.city_id','=','cities.id')
->where('users.name','LIKE',$searchText.'%') //add here your variable
->get();