如何在laravel中将记录插入到couchDB中。我已经做了检索部分,但现在我想要做插入,更新和删除。如何在laravel中插入到couchDB中
我的检索代码如下。下面
class couchdbcontroller extends Controller
{
public function getdata()
{
$content =null;
try {
$client = new Client();
$apiRequest = $client->request('GET','http://localhost:5984/user/_design/userdesign/_view/user-view?limit=20&reduce=false');
$code = $apiRequest->getBody()->getContents();
} catch (RequestException $re) {
//For handling exception
return $re->error;
}
return $code;
//return response()->json($code);
}
}
插入的代码:
public function guzzle_insert_doc()
{
$client = new Client();
$res = $client->request('PUT', 'http://localhost:5984/login/new_doc',[
'uname' => 'admin',
'password' => 'admin123',
]);
//return $res;
}
错误:客户端错误:PUT http://localhost:5984/login/new_doc
导致了400 Bad Request
响应: { “错误”: “BAD_REQUEST”, “理由”:“无效UTF- 8 JSON“}
你的问题是什么?你做过任何研究,你有什么尝试? CouchDB使用原始HTTP根据您的Client()类查询数据库,您只需执行PUT请求并在HTTP主体中传递数据库。如果您想使用现有的库或只是将其视为参考,请查看[PHP-on-Couch](https://github.com/PHP-on-Couch/PHP-on-Couch) –
我现在使用laravel从couchdb中检索数据。现在我想用laravel将数据插入到couchdb中。你能告诉我该怎么做...... Pleasae指的是我为检索部分所做的上述代码。 – Carlos
您给出的示例链接是一个php-on-couch。我没有使用该插件。我们也可以使用无插件。我已经完成了检索的一部分,但不是我没有得到什么shud我写入插入数据到couchdb像我为检索 – Carlos