Ejemplo n.º 1
0
 /**
  * @param CountryRepository $countries
  * @return bool
  */
 public function handle(CountryRepository $countries)
 {
     //the interface changes the iso_code_2 when we update a country
     //so if we check if the id in database of that iso_code is the same as the id in the input array
     //we know that the country didn't change.
     //if they are different, the country did change.
     $newCountry = $this->input['country'];
     $newCountry = $countries->findByIsoCode2($newCountry['iso_code_2']);
     if ($newCountry) {
         $this->address->fill(array_except($this->input, ['country']));
         if ($newCountry->id != $this->input['country']['id']) {
             $this->address->country()->associate($newCountry);
         }
         return $this->address->save();
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @param Address $address
  * @param CountryRepository $countries
  * @param Repository $config
  * @return bool|Address
  * @throws Exception
  */
 public function handle(Address $address, CountryRepository $countries, Repository $config)
 {
     $owners = $config->get('contact.address_owners');
     $owner = $this->resolveOwner($owners, $this->input['owner_id'], $this->input['owner_type']);
     if (is_a($owner, AddressOwner::class)) {
         //the interface changes the iso_code_2 when we update a country
         //so if we check if the id in database of that iso_code is the same as the id in the input array
         //we know that the country didn't change.
         //if they are different, the country did change.
         $newCountry = $this->input['country'];
         $newCountry = $countries->findByIsoCode2($newCountry['iso_code_2']);
         if ($newCountry) {
             $address->fill(array_except($this->input, ['country']));
             $address->country()->associate($newCountry);
             return $owner->address()->save($address) ? $address : false;
         }
     }
     return false;
 }