Laravel SQL Query

Home / Uncategorized / Laravel SQL Query

I have sample database
id | Name | Email | Group
1 John Doe A
2 Robert Chow B
3 Lee Tee C

I use autocomplete(Ajax for search and to show data on table)

On my SearchController

This is my Code
if ($request->ajax()) {
$output = "";
->where(’email’,’LIKE’,’%’ .$request->search. ‘%’ )
->orWhere(‘id’,’LIKE’,’%’ .$request->search. ‘%’)
->orWhere(‘group’,’LIKE’,’%’ .$request->search. ‘%’)

I want to have filter this that Only Group (A) should be listed on my html table

so if user search for Lee Tee it will show not belong to your Area ,

Change your where clause :$orderinfo = DB::table(‘tb_client’)
->where(function ($query) {
$query->where(’email’,’LIKE’,’%’ .$request->search. ‘%’)
->orWhere(‘id’,’LIKE’,’%’ .$request->search. ‘%’);
->where(‘group’, ‘A’)

Also I don’t recommend to use LIKE on id field!
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *