laravel condition add amount nested

  laravel, php

I’m not sure with the title, sorry for that.

I have a condition which checks if account is present and if not add the amount to the next account.

user-1 - present
user-2 - not present
user-3 - present
user-4 - not present
user-5 - present

Each user has a corresponding amount to receive, but if someone is not present the corresponding amount of him will be added to the next user. For example user-2 is not present, the corresponding amount of user-2 will be added to user-3 same with user-4 will be added to the present one.

Code: I have a condition on this, but it’s not clear for me

$check_account1 = false;
$check_account2 = false;
$user1_amount = 100;
$user2_amount = 100;

if ($account->type == "A") {
    $check_account1 = true;
    $amount = 100;
    if ($check_account1) {
        $amount = $user1_amount;
    } else {
        $amount += $user1_amount;
    }
} elseif ($account->type == "B") {
    $amount = $user2_amount;
}

$insert = new Amount;
$insert->user_id = $account->id;
$insert->amount = $amount;
$insert->save();

Source: Ask PHP

LEAVE A COMMENT