How Laravel converts parentheses into Eloquent queries
This article mainly shows you "Laravel how to convert parentheses into Eloquent query", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Laravel how to convert parentheses into Eloquent query" this article.
Convert parentheses to Eloquent queries
If you have a SQL query with a mix of and and or, something like this:
...
How to use Eloquent to translate it? Here is the wrong way:
$Q-> where ('gender',' Male'); $Q-> orWhere ('age',' > =', 18); $Q-> where ('gender',' Female'); $Q-> orWhere ('age',' > =', 65)
It's in the wrong order. The correct way to open it is a little more complicated, using closures as subqueries:
Q-> where (function ($query) {$query- > where ('gender',' Male')-> where ('age',' > =', 18);})-> orWhere (function ($query) {$query- > where ('gender',' Female')-> where ('age',' > =', 65);}) these are all the contents of the article "how Laravel converts parentheses into Eloquent query". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!