控制器变量未显示在查询生成器Laravel中 [英] Controller Variable not Showing up in Query Builder Laravel

查看:49
本文介绍了控制器变量未显示在查询生成器Laravel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如您所见,我正在从路线传递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` = ?"

这意味着查询构建器没有读取$ 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.

只是无法弄清楚为什么查询构建器无法在索引函数中提供$ merchant_url_text变量的情况下将其包含在查询中.

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.

任何建议.

推荐答案

我很确定您的代码正确. SQL输出函数toSql()不显示变量的值,出于安全原因仅输出?.

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.

这篇关于控制器变量未显示在查询生成器Laravel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆