belongsTo('App\Models\Account'); } /** * @return mixed */ public function user() { return $this->belongsTo('App\Models\User')->withTrashed(); } /** * @return mixed */ public function client() { return $this->belongsTo('App\Models\Client')->withTrashed(); } /** * @return mixed */ public function getPersonType() { return PERSON_CONTACT; } /** * @return mixed|string */ public function getName() { return $this->getDisplayName(); } /** * @return mixed|string */ public function getDisplayName() { if ($this->getFullName()) { return $this->getFullName(); } else { return $this->email; } } /** * @param $contact_key * @return mixed */ public function getContactKeyAttribute($contact_key) { if (empty($contact_key) && $this->id) { $this->contact_key = $contact_key = str_random(RANDOM_KEY_LENGTH); static::where('id', $this->id)->update(['contact_key' => $contact_key]); } return $contact_key; } /** * @return string */ public function getFullName() { if ($this->first_name || $this->last_name) { return $this->first_name.' '.$this->last_name; } else { return ''; } } /** * @return string */ public function getLinkAttribute() { return \URL::to('client/dashboard/' . $this->contact_key); } }