简体   繁体   中英

Controller Variable not Showing up in Query Builder Laravel

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM