예제 #1
0
파일: Account.php 프로젝트: abipit/crm
 /**
  * @param Contact $defaultContact
  *
  * @return Account
  */
 public function setDefaultContact($defaultContact)
 {
     if ($this->defaultContact === $defaultContact) {
         return $this;
     }
     /**
      * As resolving of $this->defaultContact->getDefaultInAccounts() lazy collection will
      * overwrite $this->defaultContact to value from db, make sure the collection is resolved
      */
     if ($this->defaultContact) {
         $this->defaultContact->getDefaultInAccounts()->toArray();
     }
     $originalContact = $this->defaultContact;
     $this->defaultContact = $defaultContact;
     if ($defaultContact) {
         $defaultContact->addDefaultInAccount($this);
     }
     if ($originalContact) {
         $originalContact->removeDefaultInAccount($this);
     }
     if ($defaultContact && !$this->contacts->contains($defaultContact)) {
         $this->addContact($defaultContact);
     }
     return $this;
 }