我有一些特价商品。每个产品都有几笔交易。我设法获得whereBetween,但仅适用于所有相关交易。我只想退回最低交易匹配whereBetween的产品。
因此,获得相关交易价格最低的产品介于给定的最小价格和最大价格之间。
到目前为止,这是我的代码:
$products = Product::when($request->filled('brand'), function ($query)use($request) {
$brandRequest = $request->input('brand');
$brandReqArray = explode(',', $brandRequest);
$query->whereHas('brands', function($q) use ($brandReqArray) {
$q->whereIn('slug', $brandReqArray);
});
})->when($request->filled('gender'), function ($query)use($request) {
$genderRequest = $request->input('gender');
$genderReqArray = explode(',', $genderRequest);
$query->whereHas('genders', function($q) use ($genderReqArray) {
$q->whereIn('slug', $genderReqArray);
});
})->when($request->filled('price'), function ($query)use($request) {
$priceRequest = $request->input('price');
$priceReqArray = explode(';', $priceRequest);
$query->whereHas('deals', function($q) use ($priceReqArray) {
$q->whereBetween('price', $priceReqArray);
});
})->with(['deals' => function ($query) {
$query->orderBy('price','asc');
}])->paginate(24);
$input = $request->only(['brands', 'gender', 'price']);
$products->appends($input);
答案 0 :(得分:0)
尝试一下,让我知道,这就是您想要的吗?
$_SESSION['GiftAdded']