My function in controller for get data when user search ajax.
This is my code:
$receiptNum = Request::get('receiptNum');
// echo $receiptNum = 123456
DB::connection()->enableQueryLog();
$q = DB::table('tbl_receipt AS r')
->join('company AS com', 'r.com_id', '=', 'com.com_id')
->join('branches AS b', 'com.b_id', '=', 'b.b_id')
->join('employee AS e', 'r.created_by', '=', 'e.e_id')
->where('r.receipt_code','=',$receiptNum)
->get();
$query = DB::getQueryLog();
var_dump($query);
I don't know what missing in my code, it's show raw sql like this:
SELECT *
FROM "tbl_receipt" AS "r"
INNER JOIN "company" AS "com" ON "r"."com_id" = "com"."com_id"
INNER JOIN "branches" AS "b" ON "com"."b_id" = "b"."b_id"
INNER JOIN "employee" AS "e" ON "r"."created_by" = "r"."e_id"
WHERE "r"."receipt_code" = ?
I trying to replace $receiptNum
by num 123
for test, it's also show ?
in raw sql
, please help me to solve it.
The "?" there are because it is a Statement. If you want a string you have to replace.
I was inspired by https://gist.github.com/JesseObrien/7418983
and for example I make this.