How to exit out of saving a record if a condition is not true

Posted 10 months ago by ekpono

I want to save a record in my table but i have set a condition that must be met before it is saved. I don't know if this is the best approach.

 public function transaction($data, $loanTransaction)
        $loanTransaction = find($data['loan_id']);
        $loanTransaction = new LoanTransaction;

        if(! $loanTransaction['amount'] === $loanTransaction->amount){

        $loanTransaction->paid_date = $loanTransaction['paid_date'];
        $loanTransaction->payment_method = $loanTransaction['payment_method'];
        $loanTransaction->bank_name = $loanTransaction['bank_account_id'];

        return true;

I want to make sure the amount entered is the same with the one in the database before saving. Am i to die or return false please which approach is the best way to go.

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