Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support whereAll/orWhereAll whereAny/orWhereAny for Hyperf\Database\Query\Builder. #6767

Merged
merged 3 commits into from
May 17, 2024

Conversation

zds-s
Copy link
Contributor

@zds-s zds-s commented May 17, 2024

Usage

whereAny

$search = '%keyword%';

// new 
User::query()
      ->whereAny([
          'first_name',
          'last_name',
          'email',
          'phone'
      ], 'LIKE', $search);
// old 
User::query()
      ->where(function ($query) use ($search) {
          $query
              ->where('first_name', 'LIKE', $search)
              ->orWhere('last_name', 'LIKE', $search)
              ->orWhere('email', 'LIKE', $search)
              ->orWhere('phone', 'LIKE', $search);
      })

SQL statment

SELECT * FROM "users" WHERE (
  "first_name" LIKE "%keyword%" 
  OR "last_name" LIKE "%keyword%" 
  OR "email" LIKE "%keyword%"
)

whereAll

// new 
$search = 'keyword';

User::whereAll([
  'first_name',
  'last_name',
  'email',
], 'LIKE', "%$search%")

// old
User::query()
      ->where(function ($query) use ($search) {
          $query
              ->where('first_name', 'LIKE', $search)
              ->where('last_name', 'LIKE', $search)
              ->where('email', 'LIKE', $search)
              ->where('phone', 'LIKE', $search);
      })

SQL statment

SELECT * FROM "users" WHERE (
  "first_name" LIKE "%keyword%" 
  AND "last_name" LIKE "%keyword%" 
  AND "email" LIKE "%keyword%"
)

huangdijia
huangdijia previously approved these changes May 17, 2024
limingxinleo
limingxinleo previously approved these changes May 17, 2024
@limingxinleo limingxinleo merged commit 4d05486 into hyperf:master May 17, 2024
64 of 65 checks passed
@zds-s zds-s deleted the support/builder branch May 17, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants