请问一下如果吧json data 和shop_id 和 admin_id 合并在一个数组呢?
laravel php ,react 这两种都可以, 有谁知道吗? 麻烦帮一下 非常感谢
Axiox post
import React, {useState} from 'react';
import axios from 'axios';
const handleProductSeletion = (data: any) => {
axios.post('/api/tracking/', {
data, //这里的数据是通过data是外部获取到的
shop_id: 12345,
admin_id: 123,
// 我想要的是 data + shop_id + admin_id 插入到数据库
});
};
Laravel Controllers Php
public function store(Request $request)
{
$result = $request->input();
return ($result);
}
后台接收到的数据数据
{
"data": [
{
"handle": "0-black",
"hasOnlyDefaultVariant": true,
"id": "6805297037467",
"images": [
{
"id": "30926270627995",
"originalSrc": "OfficialWebsite.jpg"
}
],
"productType": "",
"publishedAt": "2021-06-08T07:31:02Z",
"status": "ACTIVE"
},
{
"handle": "0-black",
"hasOnlyDefaultVariant": true,
"id": "6805297037468",
"images": [
{
"id": "30926270627995",
"originalSrc": "OfficialWebsite.jpg"
}
],
"productType": "",
"publishedAt": "2021-06-08T07:31:02Z",
"status": "ACTIVE"
},
],
"shop_id": 12345, //想合并shop_id
"admin_id": 123 //想合并admin_id
}
想要的效果
{
"data": [
{
"handle": "0-black",
"hasOnlyDefaultVariant": true,
"id": "6805297037467",
"images": [
{
"id": "30926270627995",
"originalSrc": "OfficialWebsite.jpg"
}
],
"productType": "",
"publishedAt": "2021-06-08T07:31:02Z",
"status": "ACTIVE",
"influencers_id": 123
"shop_id": 12345,
},
{
"handle": "0-black",
"hasOnlyDefaultVariant": true,
"id": "6805297037468",
"images": [
{
"id": "30926270627995",
"originalSrc": "OfficialWebsite.jpg"
}
],
"productType": "",
"publishedAt": "2021-06-08T07:31:02Z",
"status": "ACTIVE",
"admin_id": 123,
"shop_id": 12345,
},
],
}
// 结果
https://codepen.io/1567887123...