已关闭,此问题需要details or clarity。它目前不接受回答。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。
9小时前关闭。
Improve this question
我正在使用Laravel 10。我需要在这个结构中添加数据:
$json = [
"groupCode" => $groupCode,
"title" => "Solicitud de Firma",
"description" => "Solicitud de Firma - Descripción",
"customization" => [
"requestMailSubject" => "Mi Email Subject",
"requestMailBody" => "Mi Email Body",
"requestSmsBody" => "SMS Body"
],
"recipients" => [
[
"key" => "firmante01",
"presential" => true
]
],
"messages" => [
[
"document" => [
"templateType" => "base64",
"templateCode" => $templateCode, //"564FDSA4765",
"templateReference" => $pdfInBase64,
"autoFinalize" => true,
"formRequired" => true,
//"items" => $items,
],
"policies" => [
"attachments" => [], // it´s filled below
],
"metadataList" => $metaDataList,
"callbackURL" => "",
"callbackAuthorization" => "Basic " . "viafirmaapi" . ":" . "f1rm4v1420$",
"callbackMails" => "",
"callbackMailFilename" => "PRECONTRATO_" . $precontract["insert_id"]["precontract_id"] . ".pdf"
],
],
];
在这个数组中,我需要动态地将数据添加到:
"policies" => [
"attachments" => [], // it's filled below
],
为了做到这一点,我尝试:
$precontractDocument = PrecontractAttachment::where('precontract_id', $precontract["insert_id"]["precontract_id"])->get();
$attachments = [];
$document = [];
$tokens = [];
for ($i = 0; $i < count($precontractDocument); $i++) {
array_push($tokens, $this->getSecurityTokensViaFirma());
$attachments["type"] = "PDF";
$attachments["helpText"] = "Documento adjunto";
$attachments["fileReference"] = $tokens[$i];
$attachments["fileName"] = $precontractDocument[$i]["filename_result"];
$attachments["readOnly"] = true;
array_push($document, $attachments);
$this->uploadDocumentViafirma($document, $tokens, $precontract["insert_id"]["precontract_id"]);
}
// add items document into metadatalist
$json["messages"]["policies"]["attachments"] = $document;
这段代码只添加了一个文档,但是我需要将子数组数据添加到任何文档中。
我目前正在做:
// add items document into metadatalist
array_push($json["messages"]["policies"]["attachments"], $document);
但这将返回local.ERROR: array_push(): Argument #1 ($array) must be of type array, null given
我不知道我可以做些什么来添加数据:
"messages" => [
[
"policies" => [
"attachments" => [], // it´s filled below
],
]
]
1条答案
按热度按时间uujelgoq1#
试试这个
或使用以下命令更新
$json
数组: