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

[5.8] Add the dd method to the query builder #28357

Merged
merged 3 commits into from
Apr 29, 2019
Merged

[5.8] Add the dd method to the query builder #28357

merged 3 commits into from
Apr 29, 2019

Conversation

alexbowers
Copy link
Contributor

Adds the dd helper to the query builder so that you can debug queries inline.

Post::first()->comments()->dd();
Post::where('a', 'b')->where('g', 'd')->dd();

Will show you the query and bindings.

@alexbowers
Copy link
Contributor Author

The benefit of this is you can put the die dump at any point in the query build process (similar to how you can in a Collection chain).

Normally you would have to assign it to a temporary variable (which isn't necessarily easy to do, depending on how complex your query is), and then run the toSql() and getBindings() methods on the temp variable.

This allows you to not have to change your code, just put ->dd() at any point in the query building process.

@alexbowers alexbowers changed the title Add the dd method to the query builder [5.8] Add the dd method to the query builder Apr 28, 2019
@taylorotwell
Copy link
Member

I would just add it to the underlying query builder class instead of making a trait.

@alexbowers
Copy link
Contributor Author

I'll be honest, I did that originally, then thought I had to add it to all of the individual relationships. When it turned out I didn't have to do that, I forgot to revert my changes. I'll make that change now.

@alexbowers
Copy link
Contributor Author

Done.

@staudenmeir
Copy link
Contributor

I think we should name the method dump() to be consistent with similar methods in Laravel and Dusk.

@alexbowers
Copy link
Contributor Author

On Collections, the method is also called dd. Having dd is consistent with Laravel

@alexbowers
Copy link
Contributor Author

A dd is the same as a dump, except that it kills the page as well.

@staudenmeir
Copy link
Contributor

Collection contains both methods, but TestResponse and Dusk's Browser only have a dump() method that calls dd() internally. Maybe we should add both dump() and dd() to the query builder.

@taylorotwell
Copy link
Member

Should this be on the Eloquent builder or the query builder?

@staudenmeir
Copy link
Contributor

Please move the method to the query builder. This way, it is also available on the Eloquent builder.

@alexbowers
Copy link
Contributor Author

I'll move it to the Query builder so that both have it.

@taylorotwell Any thoughts on dump vs dd? Should I change it, keep it, or provide both? A dump that doesn't die seems useless, and a dump that does die seems misnamed. so unsure how I should handle that.

@alexbowers
Copy link
Contributor Author

Ok, thats changed. Now the Query Builder and Eloquent have both debug methods on them.

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