27 lines
666 B
PHP
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();
|
|
}
|
|
}
|