File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 148148 }
149149 }
150150 },
151+ {
152+ "runtime" : 120 ,
153+ "directors" : [" Alan Pakula" ],
154+ "title" : " Starting Over"
155+ },
151156 {
152157 "genres" : [" Crime" , " Drama" ],
153158 "runtime" : 119 ,
Original file line number Diff line number Diff line change @@ -381,6 +381,42 @@ wildcard characters:
381381 ...
382382 ]
383383
384+ whereLike() and whereNotLike() Methods
385+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
386+
387+ The following methods provide the same functionality as using the
388+ :ref:`like <laravel-query-builder-pattern>` query operator to match
389+ patterns:
390+
391+ - ``whereLike()``: Matches a specified pattern. By default, this method
392+ performs a case-insensitive match. You can enable case-sensitivity by
393+ passing ``true`` as the last parameter to the method.
394+ - ``whereNotLike()``: Matches documents in which the field
395+ value does not contain the specified string pattern.
396+
397+ The following example shows how to use the ``whereLike()`` method to
398+ match documents in which the ``title`` field has a value that matches the
399+ pattern ``'Start%'`` with case-sensitivity enabled:
400+
401+ .. io-code-block::
402+ :copyable: true
403+
404+ .. input:: /includes/query-builder/QueryBuilderTest.php
405+ :language: php
406+ :dedent:
407+ :start-after: begin query whereLike
408+ :end-before: end query whereLike
409+
410+ .. output::
411+ :language: json
412+ :visible: false
413+
414+ [
415+ { "title": "Start-Up", ... },
416+ { "title": "Start the Revolution Without Me", ... },
417+ ...
418+ ]
419+
384420.. _laravel-query-builder-distinct:
385421
386422Retrieve Distinct Values
You can’t perform that action at this time.
0 commit comments