49 lines
1009 B
PHP
49 lines
1009 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
class ChatWithConversation extends Model
|
||
|
|
{
|
||
|
|
protected $table = 'agent_conversations';
|
||
|
|
|
||
|
|
public $incrementing = false;
|
||
|
|
|
||
|
|
protected $keyType = 'string';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'id',
|
||
|
|
'user_id',
|
||
|
|
'title',
|
||
|
|
'chatable_type',
|
||
|
|
'chatable_id',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected static function boot(): void
|
||
|
|
{
|
||
|
|
parent::boot();
|
||
|
|
|
||
|
|
static::creating(function (ChatWithConversation $model) {
|
||
|
|
if (empty($model->id)) {
|
||
|
|
$model->id = (string) Str::uuid7();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function chatable(): MorphTo
|
||
|
|
{
|
||
|
|
return $this->morphTo();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function messages(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(AgentConversationMessage::class, 'conversation_id');
|
||
|
|
}
|
||
|
|
}
|