php - Laravel 搜索控制器

php - Laravel Search Controller

我正在尝试进行 Laravel 搜索并卡在处理点 POST 数据作为 Eloquent 方式的数组

HTML 形式如

<form>
    <select name="hidArray[]">
       <option name="test">Test</option>
       <option name="test2">Test2</option>
    </select>
</form>

现在,这个输入已经被初始化为Bootstrap Multiselect

当我得到输入作为 POST 请求时,它被表示为如下所示的数组,并且是预期的

array:2 [▼
0 => "test"
1 => "test2"
]

Now, i want to form Eloquent query to get results from database.

我试过如下:

if($request->has('hidArray')){
      $profile->whereIn('hidArray', $request->input('hidArray'));
}

但我认为,这种方式行不通。还有其他方法可以执行此操作吗?

我不太清楚你在做什么,但据我了解。

您正在尝试执行如下操作:

$profile = ModelName::where('user_id',$id);

if($request->has('hidArray')){
      $profile = $profile->whereIn('hidArray', $request->input('hidArray'));
}

$profile = $profile->get();