1/* typical query */2select * from users34/* comments added by this package */5select * from "users"/*controller='UsersController',action='index'*/;
Once this package is installed, SQL comments get automatically included, and you can control what things are added to the comments and disable comments dynamically.
1use Spatie\SqlCommenter\SqlCommenter;23SqlCommenter::addComment('foo', 'bar');45// select * from "users"/*foo='bar'*/;
This package has the concept of a "commenter" class, which add useful information to queries, such as the controller and route information. Out of the box, this package includes the following commenters:
You can also add custom commenter classes using the provided
Commenter interface from this package.
You can learn about this package, get full installation instructions, and view the source code on GitHub. The author, Freek Van der Herten, wrote a post titled Add comments to SQL queries made by Laravel if you'd like to dive deeper into the background of this package.