$notifications * @property-read \Illuminate\Database\Eloquent\Collection $purchase_order_invitations * @mixin \Eloquent */ class VendorContact extends Authenticatable implements HasLocalePreference { use Notifiable; use MakesHash; use PresentableTrait; use SoftDeletes; use HasFactory; use Searchable; /* Used to authenticate a vendor */ protected $guard = 'vendor'; protected $touches = ['vendor']; protected $presenter = VendorContactPresenter::class; /* Allow microtime timestamps */ protected $dateFormat = 'Y-m-d H:i:s.u'; protected $appends = [ 'hashed_id', ]; protected $with = []; protected $casts = [ 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', 'last_login' => 'timestamp', ]; protected $fillable = [ 'first_name', 'last_name', 'phone', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4', 'email', 'is_primary', 'vendor_id', 'send_email', ]; public function searchableAs(): string { return 'vendor_contacts_v2'; } public function toSearchableArray() { return [ 'id' => $this->company->db.":".$this->id, 'name' => $this->present()->search_display(), 'hashed_id' => $this->hashed_id, 'email' => (string)$this->email, 'first_name' => (string)$this->first_name, 'last_name' => (string)$this->last_name, 'phone' => (string)$this->phone, 'custom_value1' => (string)$this->custom_value1, 'custom_value2' => (string)$this->custom_value2, 'custom_value3' => (string)$this->custom_value3, 'custom_value4' => (string)$this->custom_value4, 'company_key' => $this->company->company_key, 'vendor_id' => $this->vendor->hashed_id, ]; } public function getScoutKey() { return $this->company->db.":".$this->id; } public function avatar() { if ($this->avatar) { return $this->avatar; } return asset('images/svg/user.svg'); } public function setAvatarAttribute($value) { if (! filter_var($value, FILTER_VALIDATE_URL) && $value) { $this->attributes['avatar'] = url('/').$value; } else { $this->attributes['avatar'] = $value; } } public function getEntityType() { return self::class; } public function getHashedIdAttribute() { return $this->encodePrimaryKey($this->id); } public function getContactIdAttribute() { return $this->encodePrimaryKey($this->id); } public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Vendor::class)->withTrashed(); } public function primary_contact() { return $this->where('is_primary', true); } public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Company::class); } public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class)->withTrashed(); } public function sendPasswordResetNotification($token) { // $this->notify(new ClientContactResetPassword($token)); } public function preferredLocale() { return once(function () { /** @var \Illuminate\Support\Collection<\App\Models\Language> */ $languages = app('languages'); $language_id = $this->company->getSetting('language_id'); return $languages->first(function ($item) use ($language_id) { return $item->id == $language_id; })->locale ?? 'en'; }); } /** * Retrieve the model for a bound value. * * @param mixed $value * @param null $field * @return Model|null */ public function resolveRouteBinding($value, $field = null) { return $this ->withTrashed() ->where('id', $this->decodePrimaryKey($value)) ->firstOrFail(); } public function purchase_order_invitations(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(PurchaseOrderInvitation::class); } public function getLoginLink() { $domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain(); return $domain.'/vendor/key_login/'.$this->contact_key; } public function getAdminLink($use_react_link = false): string { return $use_react_link ? $this->getReactLink() : config('ninja.app_url'); } private function getReactLink(): string { return config('ninja.react_url')."/#/vendors/{$this->vendor->hashed_id}"; } }