Skip to content

Commit dbd430b

Browse files
Update docs with information about the whereLike query (#9765)
* Update docs with information about the whereLike query * Update queries.md * Update queries.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 2e3c396 commit dbd430b

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

queries.md

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -583,35 +583,42 @@ You may use `whereJsonLength` method to query JSON arrays by their length:
583583
<a name="additional-where-clauses"></a>
584584
### Additional Where Clauses
585585

586-
**whereBetween / orWhereBetween**
586+
**whereLike / orWhereLike / whereNotLike / orWhereNotLike**
587587

588-
The `whereBetween` method verifies that a column's value is between two values:
588+
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:
589589

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

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

596-
The `whereNotBetween` method verifies that a column's value lies outside of two values:
596+
$users = DB::table('users')
597+
->whereLike('name', '%John%', caseSensitive: true)
598+
->get();
599+
600+
The `orWhereLike` method allows you to add an "or" clause with a LIKE condition:
597601

598602
$users = DB::table('users')
599-
->whereNotBetween('votes', [1, 100])
600-
->get();
603+
->where('votes', '>', 100)
604+
->orWhereLike('name', '%John%')
605+
->get();
601606

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

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

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

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

612-
$patients = DB::table('patients')
613-
->whereNotBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
614-
->get();
620+
> [!WARNING]
621+
> The `whereLike` case-sensitive search option is currently not supported on SQL Server.
615622
616623
**whereIn / whereNotIn / orWhereIn / orWhereNotIn**
617624

@@ -648,6 +655,36 @@ select * from comments where user_id in (
648655
> [!WARNING]
649656
> 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.
650657
658+
**whereBetween / orWhereBetween**
659+
660+
The `whereBetween` method verifies that a column's value is between two values:
661+
662+
$users = DB::table('users')
663+
->whereBetween('votes', [1, 100])
664+
->get();
665+
666+
**whereNotBetween / orWhereNotBetween**
667+
668+
The `whereNotBetween` method verifies that a column's value lies outside of two values:
669+
670+
$users = DB::table('users')
671+
->whereNotBetween('votes', [1, 100])
672+
->get();
673+
674+
**whereBetweenColumns / whereNotBetweenColumns / orWhereBetweenColumns / orWhereNotBetweenColumns**
675+
676+
The `whereBetweenColumns` method verifies that a column's value is between the two values of two columns in the same table row:
677+
678+
$patients = DB::table('patients')
679+
->whereBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
680+
->get();
681+
682+
The `whereNotBetweenColumns` method verifies that a column's value lies outside the two values of two columns in the same table row:
683+
684+
$patients = DB::table('patients')
685+
->whereNotBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
686+
->get();
687+
651688
**whereNull / whereNotNull / orWhereNull / orWhereNotNull**
652689

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

0 commit comments

Comments
 (0)