diff --git a/CHANGELOG.md b/CHANGELOG.md index 69560cbd9..83be95b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [unreleased] + +* Fix `Query\Builder::dump` and `dd` methods to dump the MongoDB query by @GromNaN in [#2727](https://github.com/mongodb/laravel-mongodb/pull/2727) + ## [4.1.2] * Fix support for subqueries using the query builder by @GromNaN in [#2717](https://github.com/mongodb/laravel-mongodb/pull/2717) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 42492a1b9..6454effbc 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -22,6 +22,7 @@ use MongoDB\BSON\Regex; use MongoDB\BSON\UTCDateTime; use MongoDB\Driver\Cursor; +use Override; use RuntimeException; use function array_fill_keys; @@ -37,6 +38,8 @@ use function call_user_func_array; use function count; use function ctype_xdigit; +use function dd; +use function dump; use function end; use function explode; use function func_get_args; @@ -250,6 +253,30 @@ public function cursor($columns = []) throw new RuntimeException('Query not compatible with cursor'); } + /** + * Die and dump the current MongoDB query + * + * @return never-return + */ + #[Override] + public function dd() + { + dd($this->toMql()); + } + + /** + * Dump the current MongoDB query + * + * @return $this + */ + #[Override] + public function dump() + { + dump($this->toMql()); + + return $this; + } + /** * Return the MongoDB query to be run in the form of an element array like ['method' => [arguments]]. * diff --git a/tests/Eloquent/CallBuilderTest.php b/tests/Eloquent/CallBuilderTest.php index 226fe1f25..fa4cb4580 100644 --- a/tests/Eloquent/CallBuilderTest.php +++ b/tests/Eloquent/CallBuilderTest.php @@ -89,19 +89,5 @@ public static function provideUnsupportedMethods(): Generator 'This method is not supported by MongoDB. Try "toMql()" instead', [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder], ]; - - yield 'dd' => [ - 'dd', - BadMethodCallException::class, - 'This method is not supported by MongoDB. Try "toMql()" instead', - [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder], - ]; - - yield 'dump' => [ - 'dump', - BadMethodCallException::class, - 'This method is not supported by MongoDB. Try "toMql()" instead', - [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder], - ]; } }