public function testStates()
 {
     $this->assertGreaterThan(count(\Addresses::getStates('CA')), count(\Addresses::getStates('US')));
     $state = State::byCountry('US')->byCode('NY')->first();
     $this->assertEquals('New York', $state->name);
     $this->assertEquals('Florida', \Addresses::stateName('FL'));
     $this->assertEquals('Nevada', \Addresses::stateName('NV', 'US'));
     $this->assertNull(State::byCountry('CA')->byCode('UT')->first());
 }
Example #2
0
 /**
  * Accept 2 digit alpha-code. Pass in the country to be extra sure you get the right name returned.
  * TODO: caching to make this fetch speedy speedy
  *
  * @param string $stateA2
  * @param string $countryA2 defaults to 'US'
  * @return $string full state/province name
  */
 public static function stateName($stateA2, $countryA2 = 'US')
 {
     if (strlen($stateA2) != 2 || strlen($countryA2) != 2) {
         throw new InvalidValueException();
     }
     if (empty($countryA2)) {
         return State::byCode($code)->firstOrFail()->name;
     }
     return Cache::rememberForever('addresses.' . $countryA2 . '.' . $stateA2 . '.state_name', function () use($stateA2, $countryA2) {
         return State::byCountry($countryA2)->byCode($stateA2)->firstOrFail()->name;
     });
 }
 public function run()
 {
     DB::table('states')->truncate();
     State::insert($this->insertList);
 }