[英]Controller Variable not Showing up in Query Builder Laravel
I am encountering a strange issue in Laravel. 我在Laravel中遇到一个奇怪的问题。
The below is an index function in one of my controllers. 下面是我的一个控制器中的索引函数。
public function index($merchant_url_text)
{
//
$deals = DB::table('tbl_deal')
-> join ('tbl_merchant', 'tbl_deal.merchant_id', '=', 'tbl_merchant.merchant_id')
-> where ('merchant_url_text', $merchant_url_text) -> toSql();
//return $merchant_url_text.$deal_id;
dd($deals);
//return $merchant_url_text;
}
As you can see I am passing merchant_url_text from route. 如您所见,我正在从路线传递merchant_url_text。
Route::get('/testroute/{merchant_url_text}', ['uses' =>'dealsVisibleController@index']);
When I am trying to debug the query by printing it, I am getting 当我尝试通过打印来调试查询时,我得到
"select * from `tbl_deal` inner join `tbl_merchant` on `tbl_deal`.`merchant_id` = `tbl_merchant`.`merchant_id` where `merchant_url_text` = ?"
This means that the query builder is not reading the $merchant_url_text variable. 这意味着查询构建器没有读取$ merchant_url_text变量。 However, when I return just that variable, it is being printed.
但是,当我只返回该变量时,它将被打印出来。
Just can't figure out why the query builder is not able to include the $merchant_url_text variable in the query when it is available in the index function. 只是无法弄清楚为什么查询构建器在索引函数中可用时无法在查询中包含$ merchant_url_text变量。
Any suggestions. 有什么建议么。
I am pretty sure that your code is correct. 我很确定您的代码是正确的。 The SQL output function
toSql()
does not show the values of variables and only prints out a ?
SQL输出函数
toSql()
不显示变量的值,而仅打印出一个?
for security reasons. 出于安全原因。
You may access all your queries by using 您可以使用来访问所有查询
$queries = DB::getQueryLog();
It is also printing the query parameters as array . 它还将查询参数打印为array 。
To get the last query: 要获取最后一个查询:
dd(end($queries));
To disable the log: 禁用日志:
DB::connection()->disableQueryLog();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.