Последняя версия с сервера прошлого разработчика
This commit is contained in:
25
app/Domain/Messenger/Models/ChatRoom.php
Executable file
25
app/Domain/Messenger/Models/ChatRoom.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Messenger\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Model;
|
||||
|
||||
class ChatRoom extends Model
|
||||
{
|
||||
|
||||
public function messsages()
|
||||
{
|
||||
return $this->hasMany(Message::class)->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
public function latestMessage()
|
||||
{
|
||||
return $this->hasOne(Message::class)->latestOfMany();
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_chat_room');
|
||||
}
|
||||
}
|
||||
24
app/Domain/Messenger/Models/Message.php
Executable file
24
app/Domain/Messenger/Models/Message.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Messenger\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Model;
|
||||
use App\Domain\Messenger\Models\ChatRoom;
|
||||
|
||||
class Message extends Model
|
||||
{
|
||||
|
||||
// protected $touches = ['room'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function room()
|
||||
{
|
||||
return $this->belongsTo(ChatRoom::class, 'chat_room_id');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user