controller - Laravel SQL Query -
i have sample database
id | name | email | group 1 john doe jdemo@yahoo.com 2 robert chow robertdemo@gmail.com b 3 lee tee leedemo@aol.com c
i use autocomplete(ajax search , show data on table)
on searchcontroller
this code
if ($request->ajax()) { $output = ""; $orderinfo=db::table('tb_client') ->where('email','like','%' .$request->search. '%' ) ->orwhere('id','like','%' .$request->search. '%') ->orwhere('group','like','%' .$request->search. '%') ->get(); }
i want have filter group (a) should listed on html table
so if user search lee tee show not belong area ,
change clause :
$orderinfo = db::table('tb_client') ->where(function ($query) { $query->where('email','like','%' .$request->search. '%') ->orwhere('id','like','%' .$request->search. '%'); }) ->where('group', 'a') ->get();
also don't recommend use on id field!
Comments
Post a Comment