app\models\Credit::apply PHP Method

apply() public method

public apply ( $amount ) : mixed
$amount
return mixed
    public function apply($amount)
    {
        if ($amount > $this->balance) {
            $applied = $this->balance;
            $this->balance = 0;
        } else {
            $applied = $amount;
            $this->balance = $this->balance - $amount;
        }
        $this->save();
        return $applied;
    }