Laravel过滤已经过滤的结果

时间:2018-02-19 11:13:23

标签: php mysql laravel laravel-5.5

我在这里获得了可用的优惠:

$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'列时,我想进行一些手动计算,如果它与所选值匹配,那么从 $ getDeals 做任何其他事情remove that row 变量,

        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
                }

            }
        }

1 个答案:

答案 0 :(得分:0)

你试试这个:$getDeals->forget($row)如果它不起作用,你可以尝试获取$ row索引和$getDeals->forget($index)!其他信息请查看此处:https://stackoverflow.com/a/37588625/8489245