【发布时间】:2019-03-29 14:59:17
【问题描述】:
我正在尝试使用 kreait/firebase-php 包更新 firebase 实时数据库。
这是我的树:
我需要更新具有is_read 值为false 的/detail/pesan/1/<unique ID> 的孩子并将其更新为true。
这是我的部分代码:
$database = $firebase->getDatabase();
$id_pesan=1;
/*
Update Firebase is_read
*/
$update = ['/is_read' => "true"];
$updatePesan_1 = $database
->getReference('chat/detail/'. $id_pesan)
->orderByChild('is_read')
->equalTo('false')
->update($update);
但我收到此错误:
Call to undefined method Kreait\Firebase\Database\Query::update()
当我先更改它以获取值然后更新/设置它:
$updatePesan_1 = $database
->getReference('chat/detail/'. $id_pesan)
->orderByChild('is_read')
->equalTo('false')
->getValue()
->set($update);
我收到此错误:
{"status":"error","error":400,"message":"索引未定义,添加\".indexOn\":\"is_read\",用于路径\"/chat/detail/ 1\",遵守规则"}
我要做的是首先过滤/查询数据库以查找具有 is_read = false 的特定树的子节点,并将值从“false”更新为“true”。
是否可以查询firebase数据库然后更新它?
如果是,我该如何修复我的代码来实现这一点?
【问题讨论】:
-
错误信息非常清楚,您需要定义一个索引。见firebase.google.com/docs/database/security/indexing-data和google.com/…"
-
为此:->getReference('chat/detail/'.$id_pesan),它达到1,但是你必须选择唯一的ID,然后它才能访问is_read
标签: php laravel firebase firebase-realtime-database