46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ChatConversation extends Model
|
|
{
|
|
protected $table = 'chat_conversations';
|
|
protected $fillable = ['contact_id', 'canal', 'estado', 'menu_actual_id', 'ultimo_mensaje_at', 'mensajes_no_leidos'];
|
|
protected $casts = ['ultimo_mensaje_at' => 'datetime'];
|
|
|
|
public function contact(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ChatContact::class, 'contact_id');
|
|
}
|
|
|
|
public function messages(): HasMany
|
|
{
|
|
return $this->hasMany(ChatMessage::class, 'conversation_id');
|
|
}
|
|
|
|
public function menuActual(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ChatMenu::class, 'menu_actual_id');
|
|
}
|
|
|
|
public function canalBadge(): string
|
|
{
|
|
return match($this->canal) {
|
|
'telegram' => '✈️ Telegram',
|
|
default => '💬 Web',
|
|
};
|
|
}
|
|
|
|
public function canalColor(): string
|
|
{
|
|
return match($this->canal) {
|
|
'telegram' => 'bg-blue-100 text-blue-700',
|
|
default => 'bg-green-100 text-green-700',
|
|
};
|
|
}
|
|
}
|