📅  最后修改于: 2022-03-11 14:54:47.849000             🧑  作者: Mango
$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();
}