Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rohansinghrawat's avatar

Required If Some value is not present In laravel validation?

Having my current requirement I have created one validations array for my request in which there are some conditions and validation is as follows

$validatorResponse = \Ipay::validator($parameters, [
            'operation' => ['required', 'in:CreateCustomer,SendTransaction,CancelTransaction,AccountNumber,BankBranchId'],
            'mobile' => ['required', ...config('instantpay.validations.mobile')],
            'customerId' => ['required_if:operation,SendTransaction'],
            'receiverId' => ['required_if:operation,SendTransaction'],
            'receiverName' => ['nullable'],
            'pinNo' => ['required_if:operation,CancelTransaction'],
            'paymentMode' => ['required_if:operation,!==,CreateCustomer'],
            'accountNumber' => ['required_if:paymentMode,!==,Cash Payment'],
            'bankBranchId' => ['required_if:paymentMode,!==,Cash Payment'],
        ]);

now I want to do something that my paymentMode is required only if operation is not Create Customer but i am not able to do so also same for account number and bankBranchId they are required if paymentMode is not Cash Payment so is there any rule or validation present in laravel which will help me in this case

Thank you

0 likes
1 reply

Please or to participate in this conversation.