Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ddFinalQuery() function #45705

Closed
wants to merge 3 commits into from
Closed

Conversation

farshidrezaei
Copy link

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

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