Function Query CouchDB Laravel
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
function query($table, $field, $urut, $limit)
{
$field = json_encode($field);
//dd($field);
$client = new Client();
$headers = [
'Content-Type' => 'application/json'
];
$body = '{
"selector": {
"table": "' . $table . '",
"data": ' . $field . '
},
"sort": [
{
"data.urut": "' . $urut . '"
}
],
"limit": ' . $limit . ',
"skip": 0,
"execution_stats": true
}';
//dd(server());
$request = new Request('POST', '' . server() . '/_find', $headers, $body);
$res = $client->sendAsync($request)->wait();
$json = $res->getBody();
$json = json_decode($json, true);
$data = $json["docs"];
// dd($data);
return $data;
}
function query_umum($q)
{
// $field = json_encode($field);
//dd($field);
$client = new Client();
$headers = [
'Content-Type' => 'application/json'
];
$body = $q;
//dd(server());
$request = new Request('POST', '' . server() . '/_find', $headers, $body);
$res = $client->sendAsync($request)->wait();
$json = $res->getBody();
$json = json_decode($json, true);
$data = $json["docs"];
// dd($data);
return $data;
}
Lanjut Part : 1
Muhammad Ullil Fahri
WA : 089696380422
Tautan WA : https://wa.me/message/SG4YA2XQP5FPE1