查询生成器Laravel中未显示控制器变量


Controller Variable not Showing up in Query Builder Laravel

我在Laravel遇到了一个奇怪的问题。

下面是我的一个控制器中的索引函数。

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;
}

正如你所看到的,我正在从路线上传递merchant_url_text。

Route::get('/testroute/{merchant_url_text}', ['uses' =>'dealsVisibleController@index']);

当我试图通过打印来调试查询时,我得到了

"select * from `tbl_deal` inner join `tbl_merchant` on `tbl_deal`.`merchant_id` = `tbl_merchant`.`merchant_id` where `merchant_url_text` = ?"

这意味着查询生成器没有读取$merchant_url_text变量。然而,当我只返回那个变量时,它正在被打印。

只是不明白为什么查询生成器不能在索引函数中提供$merchant_url_text变量时将其包含在查询中。

任何建议。

我非常确信您的代码是正确的。SQL输出函数toSql()不显示变量的值,出于安全原因,它只打印出一个?

您可以使用访问所有查询

$queries = DB::getQueryLog();

它还将查询参数打印为数组

获取最后一个查询:

dd(end($queries));

禁用日志:

DB::connection()->disableQueryLog();

有关详细信息,请参阅文档。