Craft 6 element queries are built on Laravel's query builder, providing access to Laravel's query methods alongside Craft's element-specific query methods.
This document collects practical examples, differences from Craft 5 and native Laravel, and things to watch out for when working with element queries in Craft 6. It covers filtering, ordering, retrieving and paginating elements, working with custom fields, and more advanced techniques such as reusable query conditions and raw SQL.
The focus is on PHP and Blade, but most concepts also apply to Twig when using helper functions that return element queries.
| PHP | Twig |