简体   繁体   中英

Laravel filter the result, that are already filtered

I am getting the available deals here:

$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();

My problem is when an user selects the 'estimated_profit' column, i want to do some manual calculation and if it matches the selected value, then do nothing else remove that row from $getDeals variable,

        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
                }

            }
        }

Do you try this : $getDeals->forget($row) if it does not work, you can try to get the $row index and $getDeals->forget($index) ! for other info look here : https://stackoverflow.com/a/37588625/8489245

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM