null, "message" => null, "chat_id" => null, "sender_id" => null, "receiver_id" => null, "viewed" => null, ]; protected $casts = [ "message" => "string", "chat_id" => "integer", "sender_id" => "?integer", "receiver_id" => "?integer", "viewed" => "boolean", ]; protected $dates = []; public function chat() : ?ChatEntity { $m = model(ChatModel::class); return $m->find($this->attributes['chat_id']); } /** * Notifications related with this chat entity. * * @return array */ public function notifications() : array { $m = model(ChatNotification::class); return $m->asArray()->where('chat_id',$this->attributes['chat_id'])->findAll() ?? []; } public function sentBy() : ?UserEntity { $m = model(UserModel::class); return $m->find($this->attributes["sender_id"])->withAvatar(); } public function withUser() : self { $this->attributes["user"] = $this->sentBy(); return $this; } public function getCreatedAt() { return Time::createFromFormat("Y-m-d H:i:s",$this->attributes['created_at'])->format('d/m/Y H:i'); } }