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

Update docs with information about the whereLike query #9765

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 53 additions & 16 deletions queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,35 +583,42 @@ You may use `whereJsonLength` method to query JSON arrays by their length:
<a name="additional-where-clauses"></a>
### Additional Where Clauses

**whereBetween / orWhereBetween**
**whereLike / orWhereLike / whereNotLike / orWhereNotLike**

The `whereBetween` method verifies that a column's value is between two values:
The `whereLike` method allows you to add "LIKE" clauses to your query for pattern matching. These methods provide a database-agnostic way of performing string matching queries, with the ability to toggle case-sensitivity. By default, string matching is case-insensitive:

$users = DB::table('users')
->whereBetween('votes', [1, 100])
->whereLike('name', '%John%')
->get();

**whereNotBetween / orWhereNotBetween**
You can enable a case-sensitive search via the `caseSensitive` argument:

The `whereNotBetween` method verifies that a column's value lies outside of two values:
$users = DB::table('users')
->whereLike('name', '%John%', caseSensitive: true)
->get();

The `orWhereLike` method allows you to add an "or" clause with a LIKE condition:

$users = DB::table('users')
->whereNotBetween('votes', [1, 100])
->get();
->where('votes', '>', 100)
->orWhereLike('name', '%John%')
->get();

**whereBetweenColumns / whereNotBetweenColumns / orWhereBetweenColumns / orWhereNotBetweenColumns**
The `whereNotLike` method allows you to add "NOT LIKE" clauses to your query:

The `whereBetweenColumns` method verifies that a column's value is between the two values of two columns in the same table row:
$users = DB::table('users')
->whereNotLike('name', '%John%')
->get();

$patients = DB::table('patients')
->whereBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();
Similarly, you can use `orWhereNotLike` to add an "or" clause with a NOT LIKE condition:

The `whereNotBetweenColumns` method verifies that a column's value lies outside the two values of two columns in the same table row:
$users = DB::table('users')
->where('votes', '>', 100)
->orWhereNotLike('name', '%John%')
->get();

$patients = DB::table('patients')
->whereNotBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();
> [!WARNING]
> The `whereLike` case-sensitive search option is currently not supported on SQL Server.

**whereIn / whereNotIn / orWhereIn / orWhereNotIn**

Expand Down Expand Up @@ -648,6 +655,36 @@ select * from comments where user_id in (
> [!WARNING]
> If you are adding a large array of integer bindings to your query, the `whereIntegerInRaw` or `whereIntegerNotInRaw` methods may be used to greatly reduce your memory usage.

**whereBetween / orWhereBetween**

The `whereBetween` method verifies that a column's value is between two values:

$users = DB::table('users')
->whereBetween('votes', [1, 100])
->get();

**whereNotBetween / orWhereNotBetween**

The `whereNotBetween` method verifies that a column's value lies outside of two values:

$users = DB::table('users')
->whereNotBetween('votes', [1, 100])
->get();

**whereBetweenColumns / whereNotBetweenColumns / orWhereBetweenColumns / orWhereNotBetweenColumns**

The `whereBetweenColumns` method verifies that a column's value is between the two values of two columns in the same table row:

$patients = DB::table('patients')
->whereBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();

The `whereNotBetweenColumns` method verifies that a column's value lies outside the two values of two columns in the same table row:

$patients = DB::table('patients')
->whereNotBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();

**whereNull / whereNotNull / orWhereNull / orWhereNotNull**

The `whereNull` method verifies that the value of the given column is `NULL`:
Expand Down