各位,
我想到目前为止,我已经搜索了整个stackoverflow,但我尝试的解决方案都不起作用。通过查询,我可以检索DWH.bi_Articles.No和DWH.bi_MagentoPictureBase64.No_Father之间具有一对多关系的数据。我想尝试对DWH.bi_Articles.No的结果进行分组,以便可以基于表DWH.bi_MagentoPictt获得字段ureBase 64在子数组中,但我一直得到相同的错误。
“异常:属性[Item]在此集合示例上不存在。在文件/var/www/html/RestApi/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues. php中的第950行上”
public function item_magento_mod($date_mod)
{
$items = DB::table('DWH.bi_Articoli')
->join('DWH.bi_MagentoPicture', 'DWH.bi_Articoli.No', '=', 'DWH.bi_MagentoPicture.No')
->join('DWH.bi_MagentoPictureBase64', 'DWH.bi_Articoli.No', '=', 'DWH.bi_MagentoPictureBase64.No_Father')
->where([
['DWH.bi_Articoli.AltJuiMagentoActive', '=', '1'],
['DWH.bi_Articoli.AltJuiAttributeSetId', '>', '0'],
['DWH.bi_Articoli.AltJuiAttributeSetId', '<', '99'],
['DWH.bi_Articoli.SystemModifiedAt', '>=', $date_mod],])
->orderBy('DWH.bi_Articoli.No', 'asc')
->orderBy('DWH.bi_MagentoPictureBase64.Entry_No', 'asc')
->select('DWH.bi_Articoli.No as Item',
'DWH.bi_MagentoPicture.Name',
'DWH.bi_MagentoPicture.Description',
'DWH.bi_MagentoPicture.AttributeSetId',
'DWH.bi_MagentoPicture.InArrivo',
'DWH.bi_MagentoPicture.Visibility',
'DWH.bi_MagentoPicture.Status',
'DWH.bi_MagentoPicture.VatIncluding',
'DWH.bi_MagentoPicture.Price',
'DWH.bi_MagentoPicture.EOL',
'DWH.bi_MagentoPicture.VatProdPostingGroup',
'DWH.bi_MagentoPicture.SecondaryVat',
'DWH.bi_MagentoPicture.MagikExtraFee',
'DWH.bi_MagentoPicture.Ordinabile',
'DWH.bi_MagentoPicture.Prenotabile',
'DWH.bi_MagentoPicture.Npi',
'DWH.bi_MagentoPicture.Ean',
'DWH.bi_MagentoPicture.JuiProductType',
'DWH.bi_MagentoPicture.JuiBaseProductNo',
'DWH.bi_MagentoPicture.JuiConfigurableProductNo',
'DWH.bi_MagentoPictureBase64.Entry_No',
'DWH.bi_MagentoPictureBase64.Base64Format'
)
->get();
$collection = $items->groupBy('Item')
->all();
//var_dump($collection);
return $this->handleResponse(ItemMagentoResource::collection($collection), 'All data');
}
有人有什么建议吗,我也停用了严格的数据库配置,但没有什么变化。
没有子数组的结果为:
{
"success": true,
"data": [
{
"Item": "ML343ZM/A",
"Name": "Cinturino Nike Sport Loop Nero 45mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252636480",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKELOOP",
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Item": "ML343ZM/A",
"Name": "Cinturino Nike Sport Loop Nero 45mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252636480",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKELOOP",
"Entry_No": 2,
"Base64": "imagebase64...."
},
{
"Item": "ML843ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 41mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652060",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Item": "ML843ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 41mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652060",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Entry_No": 2,
"Base64": "imagebase64...."
},
{
"Item": "ML893ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 45mm 09/21 ",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652268",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Item": "ML893ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 45mm 09/21 ",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652268",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Entry_No": 2,
"Base64": "imagebase64...."
},
{
"Item": "MM0X3ZM/A",
"Name": "Portafoglio MagSafe pelle per iPhone - Verde sequoia",
"Description": "",
"AttributeSetID": 22,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "65.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252779620",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "WALLET2021",
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Item": "MM0X3ZM/A",
"Name": "Portafoglio MagSafe pelle per iPhone - Verde sequoia",
"Description": "",
"AttributeSetID": 22,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "65.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252779620",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "WALLET2021",
"Entry_No": 2,
"Base64": "imagebase64...."
},
{
"Item": "MM0X3ZM/A",
"Name": "Portafoglio MagSafe pelle per iPhone - Verde sequoia",
"Description": "",
"AttributeSetID": 22,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "65.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252779620",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "WALLET2021",
"Entry_No": 3,
"Base64": "imagebase64...."
}
]
}
我想谈谈这个问题:
{
"success": true,
"data": [
{
"Item": "ML343ZM/A",
"Name": "Cinturino Nike Sport Loop Nero 45mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252636480",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKELOOP",
"Image":[
{
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Entry_No": 2,
"Base64": "imagebase64...."
}
]
},
{
"Item": "ML843ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 41mm 09/21",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652060",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Image":[
{
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Entry_No": 2,
"Base64": "imagebase64...."
}
]
},
{
"Item": "ML893ZM/A",
"Name": "Cinturino Nike Sport Platino/Nero 45mm 09/21 ",
"Description": "",
"AttributeSetID": 25,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "49.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252652268",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "CINTURINO_NIKE",
"Image":[
{
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Entry_No": 2,
"Base64": "imagebase64...."
}
]
},
{
"Item": "MM0X3ZM/A",
"Name": "Portafoglio MagSafe pelle per iPhone - Verde sequoia",
"Description": "",
"AttributeSetID": 22,
"InArrive": 0,
"Visibility": 4,
"Status": 1,
"VATIncluding": 1,
"Price": "65.000000",
"EOL": 1,
"VATProdPostingGroup": "SOGG.22%",
"SecondaryVAT": "SOGG.22%",
"MagikExtraFee": "",
"Ordinable": 1,
"Prenotable": 0,
"NPI": 0,
"EAN": "194252779620",
"JuiProductType": "Standard Product",
"JuiBaseProductNo": "",
"JuiConfigurableProductNo": "WALLET2021",
"Image":[
{
"Entry_No": 1,
"Base64": "imagebase64...."
},
{
"Entry_No": 2,
"Base64": "imagebase64...."
},
{
"Entry_No": 3,
"Base64": "imagebase64...."
}
]
}
]
}
项目Magento资源:
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
class ItemMagentoResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'Item' => $this->Item,
'Name' => $this->Name,
'Description' => $this->Description,
'AttributeSetID' => $this->AttributeSetId,
'InArrive' => $this->InArrivo,
'Visibility' => $this->Visibility,
'Status' => $this->Status,
'VATIncluding' => $this->VatIncluding,
'Price' => $this->Price,
'EOL' => $this->EOL,
'VATProdPostingGroup' => $this->VatProdPostingGroup,
'SecondaryVAT' => $this->SecondaryVat,
'MagikExtraFee' => $this->MagikExtraFee,
'Ordinable' => $this->Ordinabile,
'Prenotable' => $this->Prenotabile,
'NPI' => $this->Npi,
'EAN' => $this->Ean,
'JuiProductType' => $this->JuiProductType,
'JuiBaseProductNo' => $this->JuiBaseProductNo,
'JuiConfigurableProductNo' => $this->JuiConfigurableProductNo,
'Entry_No' => $this->Entry_No,
'Base64' => $this->Base64Format,
];
}
}
谢谢
1条答案
按热度按时间jucafojl1#
我猜你的错误是来自
ItemMagentoResource
类内部,而不是来自控制器groupBy('Item')
。一个简单的原因是,您应该使用
ItemMagentoResource::collection($collection)
向资源发送集合,但实际上您发送的是数组,因为$collection
包含->all()
的结果一个简单的解决方案是删除
->all()
但是,您的资源类能够处理具有分组结果的集合吗?
用这个作为回报