0

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
                }

            }
        }
arun
  • 4,595
  • 5
  • 19
  • 39

1 Answers1

0

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

Aboubacar Ouattara
  • 511
  • 1
  • 6
  • 18