使用 Laravel Fluent Query Builder,有没有办法根据 2 个子字符串搜索文本?

Using Laravel Fluent Query Builder, is there a way to search text based on 2 sub strings?

假设我在数据库中有如下所示的字符串:

The quick brown fox 0 jumps over the lazy dog 0.
The quick brown fox 0 jumps over the lazy dog 1.
The quick brown fox 0 jumps over the lazy dog 2.
The quick brown fox 1 jumps over the lazy dog 0.
The quick brown fox 1 jumps over the lazy dog 1.
The quick brown fox 1 jumps over the lazy dog 2.

有没有办法使用 Laravel Fluent Query Builder 搜索 2 个子字符串?

假设我正在寻找 "fox 0" 和 "dog"。预期结果将是:

The quick brown fox 0 jumps over the lazy dog 0.
The quick brown fox 0 jumps over the lazy dog 1.
The quick brown fox 0 jumps over the lazy dog 2.

这是我目前拥有的:

$searchStr = ["fox 0", "dog"];
$query->where('text', '=', $searchStr);

将为您提供这些结果的 SQL 查询条件是 where text like '%fox 0%' and text like '%dog%'

翻译成流畅的查询将是:

$query->where('text', 'like', '%fox 0%')->where('text', 'like', '%dog%');

或者,与您的数组保持一致:

$searchStr = ["fox 0", "dog"];
foreach($searchStr as $str) {
    $query->where('text', 'like', '%'.$str.'%');
}