Reputation: 4756
I'm trying to make an sql query which picks all the trucks with the searchTerm in the name
$foodtrucks= DB::table('foodtrucks')
->rightjoin('users', 'foodtrucks.user_id', '=', 'users.id')
->orderBy('users.premium_type','premium')
->select('foodtrucks.*')
->where('name', 'LIKE', $searchTerm)
->orWhere('info', 'LIKE', $searchTerm)
->get();
I'm currently getting the results if I write te exact name but this is not what I want to happen, I want it to display the result even it the name contains the searchTerm
so for example
I search "Truck"
I get Truck123, Truck456 and Truck789
What's happening now
I search "Truck"
I get no results
I search Truck123
I get Truck123
Upvotes: 0
Views: 44
Reputation: 13313
So you are searching for LIKE %Truck%
. Go for:
$foodtrucks= DB::table('foodtrucks')
->rightjoin('users', 'foodtrucks.user_id', '=', 'users.id')
->orderBy('users.premium_type','premium')
->select('foodtrucks.*')
->where('name', 'LIKE', "%$searchTerm%")
->orWhere('info', 'LIKE', "%$searchTerm%")
->get();
Upvotes: 1