0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. You were right. Had some issue with angular view that was not displaying data. the query was working though.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.