diff --git a/docs/includes/query-builder/QueryBuilderTest.php b/docs/includes/query-builder/QueryBuilderTest.php index 74f576e32..46822f257 100644 --- a/docs/includes/query-builder/QueryBuilderTest.php +++ b/docs/includes/query-builder/QueryBuilderTest.php @@ -374,6 +374,18 @@ public function testWhereRegex(): void $this->assertInstanceOf(\Illuminate\Support\Collection::class, $result); } + public function testWhereLike(): void + { + // begin query whereLike + $result = DB::connection('mongodb') + ->table('movies') + ->whereLike('title', 'Start%', true) + ->get(); + // end query whereLike + + $this->assertInstanceOf(\Illuminate\Support\Collection::class, $result); + } + public function testWhereRaw(): void { // begin query raw diff --git a/docs/includes/query-builder/sample_mflix.movies.json b/docs/includes/query-builder/sample_mflix.movies.json index ef8677520..2d5f45e6d 100644 --- a/docs/includes/query-builder/sample_mflix.movies.json +++ b/docs/includes/query-builder/sample_mflix.movies.json @@ -148,6 +148,11 @@ } } }, + { + "runtime": 120, + "directors": ["Alan Pakula"], + "title": "Starting Over" + }, { "genres": ["Crime", "Drama"], "runtime": 119, diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 45e3c5993..7d33c016d 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -381,6 +381,42 @@ wildcard characters: ... ] +whereLike() and whereNotLike() Methods +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following methods provide the same functionality as using the +:ref:`like ` query operator to match +patterns: + +- ``whereLike()``: Matches a specified pattern. By default, this method + performs a case-insensitive match. You can enable case-sensitivity by + passing ``true`` as the last parameter to the method. +- ``whereNotLike()``: Matches documents in which the field + value does not contain the specified string pattern. + +The following example shows how to use the ``whereLike()`` method to +match documents in which the ``title`` field has a value that matches the +pattern ``'Start%'`` with case-sensitivity enabled: + +.. io-code-block:: + :copyable: true + + .. input:: /includes/query-builder/QueryBuilderTest.php + :language: php + :dedent: + :start-after: begin query whereLike + :end-before: end query whereLike + + .. output:: + :language: json + :visible: false + + [ + { "title": "Start-Up", ... }, + { "title": "Start the Revolution Without Me", ... }, + ... + ] + .. _laravel-query-builder-distinct: Retrieve Distinct Values