diff --git a/queries.md b/queries.md index 09269b0861..d571c97954 100644 --- a/queries.md +++ b/queries.md @@ -689,23 +689,43 @@ $users = DB::table('users') ->get(); ``` -You may use `whereJsonContains` to query JSON arrays: +You may use the `whereJsonContains` and `whereJsonDoesntContain` methods to query JSON arrays: ```php $users = DB::table('users') ->whereJsonContains('options->languages', 'en') ->get(); + +$users = DB::table('users') + ->whereJsonDoesntContain('options->languages', 'en') + ->get(); ``` -If your application uses the MariaDB, MySQL, or PostgreSQL databases, you may pass an array of values to the `whereJsonContains` method: +If your application uses the MariaDB, MySQL, or PostgreSQL databases, you may pass an array of values to the `whereJsonContains` and `whereJsonDoesntContain` methods: ```php $users = DB::table('users') ->whereJsonContains('options->languages', ['en', 'de']) ->get(); + +$users = DB::table('users') + ->whereJsonDoesntContain('options->languages', ['en', 'de']) + ->get(); +``` + +In addition, you may use the `whereJsonContainsKey` or `whereJsonDoesntContainKey` methods to retrieve the results that include or do not include a JSON key: + +```php +$users = DB::table('users') + ->whereJsonContainsKey('preferences->dietary_requirements') + ->get(); + +$users = DB::table('users') + ->whereJsonDoesntContainKey('preferences->dietary_requirements') + ->get(); ``` -You may use `whereJsonLength` method to query JSON arrays by their length: +Finally, you may use `whereJsonLength` method to query JSON arrays by their length: ```php $users = DB::table('users')