['required', 'email', $this->emailUniqueRule()], 'customer_phone' => ['required'], 'billing.first_name' => 'required', 'billing.last_name' => 'required', 'billing.address_1' => 'required', 'billing.city' => 'required', 'billing.zip' => 'required', 'billing.country' => ['required', Rule::in(Country::supportedCodes())], 'billing.state' => 'required', 'create_an_account' => 'boolean', 'password' => 'required_if:create_an_account,1', 'ship_to_a_different_address' => 'boolean', 'shipping.first_name' => 'required_if:ship_to_a_different_address,1', 'shipping.last_name' => 'required_if:ship_to_a_different_address,1', 'shipping.address_1' => 'required_if:ship_to_a_different_address,1', 'shipping.city' => 'required_if:ship_to_a_different_address,1', 'shipping.zip' => 'required_if:ship_to_a_different_address,1', 'shipping.country' => ['required_if:ship_to_a_different_address,1', Rule::in(Country::supportedCodes())], 'shipping.state' => 'required_if:ship_to_a_different_address,1', 'payment_method' => ['required', Rule::in(Gateway::names())], 'terms_and_conditions' => 'accepted', ]; } private function emailUniqueRule() { return $this->create_an_account ? Rule::unique('users', 'email') : null; } }