0

I'm new at using Query Builder, today I stuck on Query Builder.I'm trying to do name column also multiple select. Here is what I'm trying to convert query builder :

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%'

is there any way without using DB::raw() ?

Thank you.

1 Answer 1

1

use join query here

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much it worked :) I understood how it work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.