如何修复“凭据”关系的“列0”不存在?

时间:2019-05-15 06:05:41

标签: laravel postgresql

这是Controller内部的内容:

DB::table('credential')->where('id', 1)->update([
    'clientid' => $credential[0]->clientid,
    'clientsecret' => $credential[0]->clientsecret,
    'redirect_uri' => $credential[0]->redirect_uri,
    'token', $curl->response->access_token
]);

但是我遇到这样的错误:

SQLSTATE[42703]: Undefined column: 7 ERROR: column "0" of relation "credential" does not exist LINE 1: ..." = $1, "clientsecret" = $2, "redirect_uri" = $3, "0" = $4, ... | (SQL: update "credential" set "clientid" = myvalue, "clientsecret" = myvalue, "redirect_uri" = http://myvalue, "0" = token, "1" = mypointvalue where "id" = 1)

有什么办法可以解决此错误吗?

1 个答案:

答案 0 :(得分:1)

问题出在查询中,'token'$curl->response->access_token被当作两个数组元素,而不是单个关联数组成员。像这样纠正它,

DB::table('credential')->where('id', 1)->update([
    'clientid' => $credential[0]->clientid,
    'clientsecret' => $credential[0]->clientsecret,
    'redirect_uri' => $credential[0]->redirect_uri,
    'token'=> $curl->response->access_token
]);