【发布时间】:2018-09-12 12:09:32
【问题描述】:
最近我正在尝试让我的 api 过滤工作。我需要像这样过滤我的产品:http://localhost/search?feature_id=1,2,3,4,5...
如果我只发送 1 个 ID,一切都很好。但是如何使它以这种方式工作呢?
这是我的控制器:
public function search2(\Illuminate\Http\Request $request) {
$query = DB::table('tlt_product_features');
if ($request->has('feature_id') ) {
$query = $query->whereIn('feature_id', [$request->get('feature_id')]);
}
$products = $query->get();
return response()->json([
'products' =>$products
]);
}
【问题讨论】: