HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/hi.naniguide.com/app/Models/UniboxContact.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class UniboxContact extends Model
{
    protected $fillable = [
        'customer_id', 'email', 'name', 'company', 'job_title',
        'phone', 'website', 'location', 'timezone', 'avatar_url',
        'tags', 'revenue', 'conversation_count', 'first_seen_at', 'last_reply_at', 'meta',
    ];

    protected $casts = [
        'tags' => 'array',
        'meta' => 'array',
        'first_seen_at' => 'datetime',
        'last_reply_at' => 'datetime',
        'revenue' => 'decimal:2',
    ];

    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    public function conversations(): HasMany
    {
        return $this->hasMany(UniboxConversation::class, 'contact_id');
    }

    public function activities(): HasMany
    {
        return $this->hasMany(UniboxContactActivity::class, 'contact_id');
    }

    public function getDisplayNameAttribute(): string
    {
        return $this->name ?: $this->email;
    }

    public function getFormattedRevenueAttribute(): string
    {
        if ($this->revenue >= 1000) {
            return '$' . round($this->revenue / 1000, 1) . 'k';
        }
        return '$' . number_format($this->revenue, 0);
    }
}