Skip to content

Commit 5d55ebd

Browse files
committed
DOCSP-42818: wherelike and wherenotlike docs
1 parent a2eb54a commit 5d55ebd

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

docs/includes/query-builder/QueryBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ public function testWhereRegex(): void
374374
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
375375
}
376376

377+
public function testWhereLike(): void
378+
{
379+
// begin query whereLike
380+
$result = DB::connection('mongodb')
381+
->table('movies')
382+
->whereLike('title', 'Start%', true)
383+
->get();
384+
// end query whereLike
385+
386+
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
387+
}
388+
377389
public function testWhereRaw(): void
378390
{
379391
// begin query raw

docs/includes/query-builder/sample_mflix.movies.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
}
149149
}
150150
},
151+
{
152+
"runtime": 120,
153+
"directors": ["Alan Pakula"],
154+
"title": "Starting Over"
155+
},
151156
{
152157
"genres": ["Crime", "Drama"],
153158
"runtime": 119,

docs/query-builder.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,45 @@ To learn more about regular expression queries in MongoDB, see
847847
:manual:`$regex </reference/operator/query/regex/>`
848848
in the {+server-docs-name+}.
849849

850+
whereLike() and whereNotLike() Methods
851+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
852+
853+
You can perform queries to match string patterns by using the
854+
following methods:
855+
856+
- ``whereLike()``: Matches a specified pattern. By default, this method
857+
performs a case-insensitive match. You can enable case-sensitivity by
858+
passing ``true`` as the last parameter to the method.
859+
- ``whereNotLike()``: Matches documents in which the field
860+
value does not contain the specified string pattern.
861+
862+
The following example shows how to use the ``whereLike()`` method to
863+
match documents in which the ``title`` field has a value that matches the
864+
pattern ``'Start%'`` with case-sensitivity enabled:
865+
866+
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
867+
:language: php
868+
:dedent:
869+
:start-after: begin query whereLike
870+
:end-before: end query whereLike
871+
872+
The preceding query matches documents with the following ``title``
873+
field values:
874+
875+
.. code-block:: none
876+
877+
Start-Up
878+
Start the Revolution Without Me
879+
Starting Over
880+
881+
The query doesn't match the following ``title`` values:
882+
883+
.. code-block:: none
884+
885+
Restart
886+
starting over
887+
I Start Counting
888+
850889
.. _laravel-query-builder-whereRaw:
851890

852891
Run MongoDB Query API Operations Example

0 commit comments

Comments
 (0)