Initial commit
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
ssww23
2026-03-10 00:55:37 +03:00
parent fc0f28d830
commit 93a655235a
155 changed files with 24768 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ChatConversation extends Model
{
use HasFactory;
public const STATUS_OPEN = 'open';
public const STATUS_CLOSED = 'closed';
protected $fillable = [
'user_id',
'visitor_token',
'status',
'last_message_at',
];
protected function casts(): array
{
return [
'last_message_at' => 'datetime',
];
}
public function user()
{
return $this->belongsTo(User::class);
}
public function messages()
{
return $this->hasMany(ChatMessage::class);
}
public function latestMessage()
{
return $this->hasOne(ChatMessage::class)->latestOfMany();
}
public function getDisplayNameAttribute(): string
{
if ($this->user?->name) {
return $this->user->name;
}
return 'Гость #' . $this->id;
}
public function isClosed(): bool
{
return $this->status === self::STATUS_CLOSED;
}
}