Controller Variable not Showing up in Query Builder Laravel

大憨熊 提交于 2019-12-14 03:20:02

问题


I am encountering a strange issue in 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.

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. 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.

Any suggestions.


回答1:


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 ? for security reasons.




回答2:


You may access all your queries by using

$queries = DB::getQueryLog();

It is also printing the query parameters as array.

To get the last query:

dd(end($queries));

To disable the log:

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

See the docs for further information.



来源:https://stackoverflow.com/questions/34279635/controller-variable-not-showing-up-in-query-builder-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!