最近我试图创建产品比较api,返回如下项目数组:localhost:8000 / products /?compare = 1-2-3(product id's)等。但是,不幸的是,我不是能够做到这一点。我只设法归还一个。有没有机会我可以将id的数组传递给控制器以收集在url中用破折号分隔的项目数组?这是我的控制器功能。
public function getProduct($id){
$tlt_products = DB::table('tlt_products')->find($id);
$tlt_products_features_id = DB::table('tlt_product_features')->where('product_id', $id)->get()->pluck('feature_id');
$tlt_features = DB::table('tlt_features')->whereIn('id', $tlt_products_features_id)->get()->groupBy('feature_group');
$tlt_feature_groups = DB::table('tlt_features')->groupBy('feature_group')->get()->toArray();
return response()->json([
'product' => $tlt_products,
'product_features' => $tlt_features,
'feature_groups' => $tlt_feature_groups
]);
}
这是我的路线:
$router->get('products/{id}','ProductController@getProduct');