55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ChatMessage extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'message',
|
|
'reply_to_id',
|
|
'is_deleted',
|
|
'deleted_by',
|
|
];
|
|
|
|
/**
|
|
* Cast attributes.
|
|
* Encrypt chat messages at rest.
|
|
*/
|
|
protected $casts = [
|
|
'message' => 'encrypted',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function replyTo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'reply_to_id');
|
|
}
|
|
|
|
public function replies(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'reply_to_id');
|
|
}
|
|
|
|
public function reactions(): HasMany
|
|
{
|
|
return $this->hasMany(ChatMessageReaction::class, 'message_id');
|
|
}
|
|
|
|
public function deletedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'deleted_by');
|
|
}
|
|
}
|