我正在从JSON API获取数据,该JSON API还返回具有大量数字的对象(uint8)。这是一个示例:
{
"chordID": "d7604de9aa22e2626a690fb0b3ec2c4ef4c790d73679e56ce0d5fa2f77befba0",
"consensusData": 11689184649718456000,
"hash": "c785277874464590ce77b2e59df198a670ba8807f51ce2a6f4b32f38033ac4f8",
"height": 1,
"nextBookKeeper": "0000000000000000000000000000000000000000",
"prevBlockHash": "1a4f55a1164ea4b8de29484eb790bffa3f5b1a7ccbc3f323142aa1ae3e93b742",
"program": {
"code": "00",
"parameter": "00"
},
"signature": "3f2f01c72a3f1a00a54cf72a6fa1c28b64ac1f9bd4c06303591e20b1846c13a0b86de04c67bcb526184a92f1f697f884b8ae88a4c80eb3076d0a8a18dbb52403",
"signer": "040149c42944eea91f094c16538eff0449d4d1e236f31c8c706b2e40e98402984c",
"stateRoot": "1966dbb876e96c4fa8c77490548c00014607ab8050014588f209451cd19a1b1a",
"timestamp": 1553077869,
"transactionsRoot": "578a7b6b1802effaa8a4cca5d56cb0b6c37bd6ce830496dc3d2f546bf1ed48c8",
"version": 1,
"winnerHash": "0000000000000000000000000000000000000000000000000000000000000000",
"winnerType": "GenesisSigner"
}
现在我想直接通过以下方式保存此数据:
$transaction = new Transaction($response["result"]);
Laravel出现错误,因为数字被转换为指数写:
array:15 [
"chordID" => "d7604de9aa22e2626a690fb0b3ec2c4ef4c790d73679e56ce0d5fa2f77befba0"
"consensusData" => 1.1689184649718E+19
"hash" => "c785277874464590ce77b2e59df198a670ba8807f51ce2a6f4b32f38033ac4f8"
"height" => 1
"nextBookKeeper" => "0000000000000000000000000000000000000000"
"prevBlockHash" => "1a4f55a1164ea4b8de29484eb790bffa3f5b1a7ccbc3f323142aa1ae3e93b742"
"program" => array:2 [
"code" => "00"
"parameter" => "00"
]
"signature" => "3f2f01c72a3f1a00a54cf72a6fa1c28b64ac1f9bd4c06303591e20b1846c13a0b86de04c67bcb526184a92f1f697f884b8ae88a4c80eb3076d0a8a18dbb52403"
"signer" => "040149c42944eea91f094c16538eff0449d4d1e236f31c8c706b2e40e98402984c"
"stateRoot" => "1966dbb876e96c4fa8c77490548c00014607ab8050014588f209451cd19a1b1a"
"timestamp" => 1553077869
"transactionsRoot" => "578a7b6b1802effaa8a4cca5d56cb0b6c37bd6ce830496dc3d2f546bf1ed48c8"
"version" => 1
"winnerHash" => "0000000000000000000000000000000000000000000000000000000000000000"
"winnerType" => "GenesisSigner"
]
这是我的数据库架构:
Schema::create('headers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('block_id');
$table->binary('hash');
$table->integer('version')->unsigned();
$table->binary('prevBlockHash');
$table->binary('transactionsRoot');
$table->binary('stateRoot');
$table->bigInteger('timestamp');
$table->integer('height')->unsigned();
$table->bigInteger('consensusData')->unsigned();
$table->binary('nextBookKeeper');
$table->binary('winnerHash');
$table->enum('winnerType', ['GenesisSigner', 'TxnSigner', 'BlockSigner']);
$table->binary('signer');
$table->binary('chordID');
$table->timestamps();
$table->foreign('block_id')
->references('id')->on('blocks')
->onDelete('cascade');
});
默认情况下是否有任何方法可以阻止该类型的转换?我在laravel后端使用pgsql数据库。