Skip to content

add ddFinalQuery() function#45705

Closed
farshidrezaei wants to merge 3 commits intolaravel:9.xfrom
farshidrezaei:patch-1
Closed

add ddFinalQuery() function#45705
farshidrezaei wants to merge 3 commits intolaravel:9.xfrom
farshidrezaei:patch-1

Conversation

@farshidrezaei
Copy link
Copy Markdown

This function replace bind bindings in to query and die and dump final query. when you debugging complicated queries, you need to get final query without complexity.

if you do like bellow :

User::where('name','farshid')->dd(); 

For example you will get bellow result:

"SELECT * FROM users WHERE name=?;",
[
  0 => "farshid"
]

But if you calling

User::where('name','farshid')->ddFinalQuery(); 

You will get bellow result:

"SELECT * FROM users WHERE name='farshid';"

This function replace bind bindings in to query and die and dump final query.
when you debugging complicated queries, you need to get final query without complexity.

if you do like bellow :
```php
User::where('name','farshid')->dd(); 
```
For example you will get bellow result:
```
"SELECT * FROM users WHERE name=?;",
[
  0 => "farshid"
]
```

But if you calling
```php
User::where('name','farshid')->ddFinalQuery(); 
```
You will get bellow result:
```
"SELECT * FROM users WHERE name='farshid';"
```
@dennisprudlo
Copy link
Copy Markdown
Contributor

We all want such a function, however it is not as easy as it seems 😅 #39551 mentions the problems for postgresql in a comment (#38027 (comment))

@taylorotwell
Copy link
Copy Markdown
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@nathanjansen
Copy link
Copy Markdown

nathanjansen commented Mar 26, 2023

@farshidrezaei I decided to create a package for this :)
https://github.com/uteq/laravel-query-builder-macros

Example code:

Account::query()
    ->where('email', 'john')
    ->ddQuery();
// dd() of `select * from "account" where "email" = 'john'`

@farshidrezaei
Copy link
Copy Markdown
Author

@nathanjansen that's good. i will contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants