Laravel过滤结果,已经过滤的
Laravel filter the result, that are already filtered
我在这里获取可用的交易:
$buildQuery = Deals::with(['market:id,name','propertyType:id,name','dealStatus:id,name']);
if($request->filled('property_type')){
$buildQuery->where('property_type_id', $request->property_type);
}
if($request->filled('purchase_price')){
$price = explode("-",$request->purchase_price);
$min_price = (int)$price[0];
$max_price = (int)$price[1];
$buildQuery->whereBetween('purchase_price', [$min_price, $max_price]);
}
if($request->filled('status')){
$buildQuery->where('status', $request->status);
}
$getDeals = $buildQuery->whereIn('deal_status_id',$dealStatua)
->whereIn('market_id',$getMarket)
->orderBy('id')->get();
我的问题是当用户选择 'estimated_profit'
列时,我想进行一些手动计算,如果它与所选值匹配,则什么都不做 remove that row
from $getDeals 变量,
if($request->filled('estimated_profit')){
foreach($getDeals as $row){
$deal = Deal::find($row->id);
$purchase_price = $deal->purchase_price;
$cost_of_price = $deal->cost_of_price;
$arv_price = $deal->arv_price;
$calculated_estimated_profit = $arv_price - ( $purchase_price + $cost_of_price );
$price = explode("-",$request->estimated_profit);
$min_price = (int)$price[0];
$max_price = (int)$price[1];
if($calculated_estimated_profit >= $min_price && $calculated_estimated_profit <= $max_price){
// dont do anything here
}else{
// dont want that row here
}
}
}
你试试这个:$getDeals->forget($row)
如果它不起作用,你可以尝试获取 $row 索引和 $getDeals->forget($index)
!其他信息看这里:
我在这里获取可用的交易:
$buildQuery = Deals::with(['market:id,name','propertyType:id,name','dealStatus:id,name']);
if($request->filled('property_type')){
$buildQuery->where('property_type_id', $request->property_type);
}
if($request->filled('purchase_price')){
$price = explode("-",$request->purchase_price);
$min_price = (int)$price[0];
$max_price = (int)$price[1];
$buildQuery->whereBetween('purchase_price', [$min_price, $max_price]);
}
if($request->filled('status')){
$buildQuery->where('status', $request->status);
}
$getDeals = $buildQuery->whereIn('deal_status_id',$dealStatua)
->whereIn('market_id',$getMarket)
->orderBy('id')->get();
我的问题是当用户选择 'estimated_profit'
列时,我想进行一些手动计算,如果它与所选值匹配,则什么都不做 remove that row
from $getDeals 变量,
if($request->filled('estimated_profit')){
foreach($getDeals as $row){
$deal = Deal::find($row->id);
$purchase_price = $deal->purchase_price;
$cost_of_price = $deal->cost_of_price;
$arv_price = $deal->arv_price;
$calculated_estimated_profit = $arv_price - ( $purchase_price + $cost_of_price );
$price = explode("-",$request->estimated_profit);
$min_price = (int)$price[0];
$max_price = (int)$price[1];
if($calculated_estimated_profit >= $min_price && $calculated_estimated_profit <= $max_price){
// dont do anything here
}else{
// dont want that row here
}
}
}
你试试这个:$getDeals->forget($row)
如果它不起作用,你可以尝试获取 $row 索引和 $getDeals->forget($index)
!其他信息看这里: