I have 2 tables Orders
and Products
. In orders
table has foreign key product_id
. Sometimes it's not necessary that order must contain the product(order without any product id is allowed). In this scenario my existIn validation rule causing the problem to save data.
$rules->add($rules->existsIn(['product_id'], 'Products')); //Validation in the model of Orders.
N.B. - Keep in mind that I have allowed product_id to be null in my DB.