<?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');
    }
}
