Join the community and participate in the ongoing discussions. Join Now!
Updating table column using dynamic values based on result of computation

Am trying update a particular column in my table, with dynamic values based on the Fund Balance.

public function update(){
        //
        $retrievefund = payment::all();
        foreach($retrievefund as $value){
            $getearning = $value->earnamount;
            $saverecored = $this->checkfund($getearning);
            DB::update('update payments set earnamount = ?',[$saverecored]);
            return redirect()->back();
        }
}     

Below is where an computing my values based on percentage and fund balance:

public function checkfund(){
        $retrievefund = payment::all();
        foreach($retrievefund as $value){
            $fund = $value->fundamount;
            $cearn = $value->earnamount;
            if($fund < 100){
                $earn = 3 * $fund / 100;
                $saveEarn = $cearn + $earn;
            }elseif($fund >= 100 && $fund <= 299){
                $earn = 5 * $fund / 100;
                $saveEarn = $cearn + $earn;
            }elseif($fund >= 300 && $fund <= 499){
                $earn = 7 * $fund / 100;
                $saveEarn = $cearn + $earn;
            }else{
                $earn = 10 * $fund / 100;
                $saveEarn = $cearn + $earn;
            }
        }
        return $saveEarn;
    }

Please see to the code.

NNA OKECHI NOBLE
08th May, 2020 @ 04:08 pm