From 3fd7859f6ecd761f18a429ea75fa34a0746e1de5 Mon Sep 17 00:00:00 2001 From: Damien MATHIEU Date: Fri, 1 Aug 2025 15:03:35 +0200 Subject: [PATCH] Update note for MySql strict mode --- database/relations.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/database/relations.md b/database/relations.md index 2d8ead82..e2e7c646 100644 --- a/database/relations.md +++ b/database/relations.md @@ -1176,7 +1176,18 @@ You may also specify an operator and count to further customize the query: $posts = Post::has('comments', '>=', 3)->get(); ``` -> **NOTE**: MySQL strict mode can sometimes complain when using a `GROUP` column without a `GROUP BY` clause (in the above case, `COUNT()`). You can set the `strict` option to `false` in your database's connection configuration (i.e. `database.connections.mysql.strict`) to ignore this warning message. +> **NOTE**: MySQL strict mode can sometimes complain when using a `GROUP` column without a `GROUP BY` clause (in the above case, `COUNT()`). To ignore this warning message, you can set the `strict` option to `false` in your database's connection configuration (i.e. `database.connections.mysql.strict`) or disable the `strict` option the time of running your query (see below). + +```php +// Disable mysql strict mode +config()->set('database.connections.mysql.strict', false); +DB::reconnect(); +// Retrieve all posts that have three or more comments... +$posts = Post::has('comments', '>=', 3)->get(); +// Re-enable mysql strict mode +config()->set('database.connections.mysql.strict', true); +DB::reconnect(); +``` Nested `has` statements may also be constructed using "dot" notation. For example, you may retrieve all posts that have at least one comment and vote: