mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
feat : migration and chat models
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
namespace App\Models\Chat;
|
||||
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
@ -12,7 +13,10 @@ class ChatModel extends Model
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [];
|
||||
protected $allowedFields = [
|
||||
"pedido_id",
|
||||
"chat_department_id"
|
||||
];
|
||||
|
||||
protected bool $allowEmptyInserts = false;
|
||||
protected bool $updateOnlyChanged = true;
|
||||
@ -44,20 +48,23 @@ class ChatModel extends Model
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
|
||||
|
||||
public function getChat(int $chat_id)
|
||||
{
|
||||
$this->db->table('chats')
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
"users.id as userId",
|
||||
"users.email",
|
||||
"chat_messages.created_at as messageCreatedAt",
|
||||
"chat_messages.message as messageText",
|
||||
]
|
||||
)
|
||||
->join("users","users.id == chat_messages.user_id","left")
|
||||
->join("chat_messages","chats.id == chat_messages.chat_id","left");
|
||||
|
||||
->select(
|
||||
[
|
||||
"chats.id as chatId",
|
||||
"users.id as userId",
|
||||
"chats.pedido_id as pedidoId",
|
||||
"users.email",
|
||||
"chat_messages.created_at as messageCreatedAt",
|
||||
"chat_messages.message as messageText",
|
||||
]
|
||||
)
|
||||
->join("users", "users.id == chat_messages.user_id", "left")
|
||||
->join("chat_deparments", "chat_deparments.id == chats.chat_deparment_id", "left")
|
||||
->join("chat_messages", "chats.id == chat_messages.chat_id", "left")
|
||||
->where("chatId", $chat_id)->get()->getResultObject();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user