Skip to content

Conversation

@josepostiga
Copy link
Contributor

@josepostiga josepostiga commented Oct 23, 2025

This PR adds a new method to the database query builder class: comment(), which enables a user-defined comment string to be appended to the end of a query.

For example, executing DB::from('users)->comment('Getting all users')->get(); generates the following query:

select * from users /* Getting all users */

Why?

Too many times, while looking at running queries in a specific database instance, I wanted to have a quick way to know where a given query is being executed. I thought that a simple comment could allow for that little extra context on where it's running, much like code comments.

I honestly don't know if all other database engines strip away these comments, but the one I use the most (MySQL) seems to show this information when running show full processlist.

Docs

If this PR gets merged, I'll open a PR to update the docs.

@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 applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@josepostiga josepostiga deleted the feat/add-support-for-comment-queries branch October 24, 2025 08:03
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.

2 participants