Skip to content

Commit

Permalink
Altered validation config to also cover country code validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SteJaySulli committed Oct 13, 2020
1 parent cee12a4 commit f0115e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public function getHumanReadableAttribute(): string

public function validate(): void
{
if (!$this->country) {
if (config('addresses.validation.country-code') && !$this->country) {
throw new InvalidCountryException();
}

switch ($this->country->isoCodeAlpha3) {
case 'GBR':
if (config('addresses.gbr-validation.enabled') && !Validator::validatePostcode($this->postcode)) {
if (config('addresses.validation.uk-postcode') && !Validator::validatePostcode($this->postcode)) {
throw new InvalidUKPostcodeException();
}
break;
Expand Down
5 changes: 3 additions & 2 deletions src/config/addresses.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

return [
'gbr-validation' => [
'enabled' => true
'validation' => [
'uk-postcode' => true,
'country-code' => true,
],
'geocoding' => [
'enabled' => true,
Expand Down

0 comments on commit f0115e1

Please sign in to comment.