Reputation: 165
I want to use concat with eloquent , I have two tables (users) and (cars) From users table I want to use first_name , last_name fields, and from cars table I want to use field called (vin).
$cars = Car::where(DB::raw('concat(first_name," ",vin," ",make)') , 'LIKE' , '%$search%')->paginate();
first_name field from Users table and the rest from Cars table
Upvotes: 2
Views: 3377
Reputation: 17658
You can use join()
for this as:
$cars = Car::join('users', 'cars.user_id', '=', 'users.id')
->where(DB::raw('concat(users.first_name," ",cars.vin," ",cars.make)') , 'LIKE' , "%$search%")
->select('cars.*')
->paginate();
Upvotes: 1