📌  相关文章
📜  使用多个单词搜索的值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:54.078000             🧑  作者: Mango

代码示例1
$string = 'john  doe';

// split on 1+ whitespace & ignore empty (eg. trailing space)
$searchValues = preg_split('/s+/', $string, -1, PREG_SPLIT_NO_EMPTY); 

$users = User::where(function ($q) use ($searchValues) {
  foreach ($searchValues as $value) {
    $q->orWhere('name', 'like', "%{$value}%");
  }
})->get();