feat: add Reverb realtime messaging

This commit is contained in:
2026-03-21 12:51:59 +01:00
parent 60f78e8235
commit e8b5edf5d2
45 changed files with 3609 additions and 339 deletions

View File

@@ -7,8 +7,11 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use App\Models\MessageRead;
/**
* @property int $id
* @property int $conversation_id
@@ -24,16 +27,31 @@ class Message extends Model
use HasFactory, SoftDeletes, Searchable;
protected $fillable = [
'uuid',
'client_temp_id',
'conversation_id',
'sender_id',
'message_type',
'body',
'meta_json',
'reply_to_message_id',
'edited_at',
];
protected $casts = [
'meta_json' => 'array',
'edited_at' => 'datetime',
];
protected static function booted(): void
{
static::creating(function (self $message): void {
if (! $message->uuid) {
$message->uuid = (string) Str::uuid();
}
});
}
// ── Relationships ────────────────────────────────────────────────────────
public function conversation(): BelongsTo
@@ -56,9 +74,14 @@ class Message extends Model
return $this->hasMany(MessageAttachment::class);
}
public function setBodyAttribute(string $value): void
public function reads(): HasMany
{
$sanitized = trim(strip_tags($value));
return $this->hasMany(MessageRead::class);
}
public function setBodyAttribute(?string $value): void
{
$sanitized = trim(strip_tags((string) $value));
$this->attributes['body'] = $sanitized;
}