jay_gorio
248
11
Laravel

How to validate if sum of values are equal in Validation

Posted 1 year ago by jay_gorio

I have this accounting project where I need to validate if debit and credit are equal before saving to the database.

e.g

postings: [
    {

        id: 1,
        account_id: 1,
        debit:  1000
    },
    {
        id: 2,
        account_id: 5,
        credit: 1500
    },
    {
        id: 3,
        account_id: 8,
        debit: 500
    }
]

By the way I am using axios and lodash.

axios.post('/api/journals', {

    postings : map(this.accounts, function(account) {

        account_id: account.account_id,
        debit: account.debit,
        credit: account.credit
    })
}

Can anyone suggest how to implement this validation rule.

Please sign in or create an account to participate in this conversation.