feat: add Reverb realtime messaging
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user