Saturday, April 15, 2017

Laravel : QUERY BUILDER SELECT ON WHERE LIKE STATEMENT

I have a Query Builder problem on Laravel 5.4,

I want to select only certain field on where statement.

if I don't put WHERE statement function the SELECT function performed nicely, but when I put WHERE LIKE function then seems the SELECT function not working and it automatically selecting all (*)

Fyi, both user and address table has 'name' field. it only select name from user table. it work nicely.

DB::table('user')
-leftJoin('address', 'user.id', '=', 'address.user_id')
->select('user.name')
->get();

but this is not working

DB::table('user')
-leftJoin('address', 'user.id', '=', 'address.user_id')
->select('user.name')
->where('user.name', 'LIKE', '%jhon%')
->get();

how do I accomplish this? Any anwer will be highly appreciated!



via Angger

Advertisement