Skip to content

Conversation

@einar-hansen
Copy link
Contributor

@einar-hansen einar-hansen commented Jul 25, 2024

This pull request complements the work done by @musiermoore in the PR 50344 where the whereAny and whereAll methods were added to the framework. The new whereNone method is the often more forgotten "little sibling" / negative path function to complete this family of methods.

Similar to whereAny and whereAll, the whereNone method operates on multiple columns, but it uses negation to achieve the opposite effect of whereAny. This method gives users the ability to query for records where none of the specified columns match the given condition, thus completing the logical triad of "any", "all", and "none".

The whereNone method works as follows:

$users = DB::table('users')
            ->where('active', true)
            ->whereNone([
                'first_name',
                'last_name',
                'email',
            ], 'LIKE', 'einar%')
            ->get();

This will generate the following SQL:

SELECT *
FROM users
WHERE active = true AND NOT (
    first_name LIKE 'einar%' OR
    last_name LIKE 'einar%' OR
    email LIKE 'einar%'
)

By adding whereNone, we complete the set of methods for handling constraints across multiple columns.

@einar-hansen
Copy link
Contributor Author

I've also added a draft PR with documentation of the method to the laravel/docs repository.

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.

3 participants