📜  从可标记的 laravel 过滤 - PHP 代码示例

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

代码示例1
$searchdata = ['A','B']; //keep it as an array
if(count($searchdata) > 1) {
    $data = User::with('tags')
                      ->orWhereHas('tags', function($q) use ($searchdata){
                            $q->whereIn('name', $searchdata);
                      })->get();

} else {
    $data = User::with('tags')
                      ->orWhereHas('tags', function($q) use ($searchdata){
                            $q->where('name', 'LIKE', '%' . $searchdata[0] . '%');
                       })->get();

}