Initialer Laravel Commit für BetiX
This commit is contained in:
54
app/Models/ChatMessage.php
Normal file
54
app/Models/ChatMessage.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user