protected function linkContactToUser(Contact $contact)
 {
     if ($contact->email === null) {
         return $this;
     }
     $user = User::where(['email' => $contact->email])->first();
     if ($user === null) {
         $contact->user()->dissociate();
         $contact->save();
         return $this;
     }
     $contact->user()->associate($user);
     $contact->save();
     return $this;
 }
Exemple #2
0
 /**
  * Update Contact attributes.
  *
  * @param Business $business
  * @param Contact  $contact
  * @param array    $data
  * @param string   $notes
  *
  * @return void
  */
 public function update(Business $business, Contact $contact, $data = [], $notes = null)
 {
     $birthdate = array_get($data, 'birthdate');
     $this->sanitizeDate($birthdate);
     $contact->firstname = array_get($data, 'firstname');
     $contact->lastname = array_get($data, 'lastname');
     $contact->email = array_get($data, 'email');
     $contact->nin = array_get($data, 'nin');
     $contact->gender = array_get($data, 'gender');
     $contact->birthdate = $birthdate;
     $contact->mobile = array_get($data, 'mobile');
     $contact->mobile_country = array_get($data, 'mobile_country');
     $contact->postal_address = array_get($data, 'postal_address');
     $contact->save();
     self::updateNotes($business, $contact, $notes);
     return $contact;
 }
Exemple #3
0
 public function linkToUserId(Contact $contact, $userId)
 {
     $contact->user()->associate($userId);
     $contact->save();
     return $contact->fresh();
 }