use App\User; // Create a new query object for the "users" table $query = User::newQuery(); // Add a where clause to the query $query->where('name', 'John Doe'); // Execute the query and get the results $results = $query->get();
use Doctrine\ORM\EntityManagerInterface; use App\Entity\User; // Get the Doctrine entity manager $entityManager = getEntityManager(); // Create a new query object for the User entity $qb = $entityManager->getRepository(User::class)->newQuery(); // Build the query to select all users $qb->select('u') ->from(User::class, 'u'); // Execute the query and get the results $results = $qb->getQuery()->getResult();Overall, the static newQuery method is a powerful tool for building and executing flexible database queries in PHP, and is commonly used in popular package libraries like Laravel Eloquent and Doctrine ORM.