Files
sirpremiumv2/app/Models/ChatContact.php
T
2026-04-30 21:32:32 -05:00

27 lines
666 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ChatContact extends Model
{
protected $table = 'chat_contacts';
protected $fillable = ['canal', 'canal_id', 'nombre', 'telefono', 'metadata'];
protected $casts = ['metadata' => 'array'];
public function conversations(): HasMany
{
return $this->hasMany(ChatConversation::class, 'contact_id');
}
public function activeConversation(): ?ChatConversation
{
return $this->conversations()
->whereIn('estado', ['bot', 'agente'])
->latest()
->first();
}
}