```ruby=
function create($product) {
if($product->store->platform('tribelio')) {
$productdata = $this->getProductData($product);
$response = TribelioService::createProduct($productdata, $product->store->platform('tribelio'));
if(isset($response['data']['productId'])) {
ProductPlatform::create(array(
'product_id' => $product->id,
'platform' => 'tribelio',
'platform_product_id' => $response['data']['productId']
));
}
if(!empty($response['errMessage'])){
$storePlatform = $product->design->storePlatforms()->where('platform','tribelio')->first();
$data = json_decode($storePlatform->pivot->data);
$collect = collect($data);
#
$collectProduct = $collect->firstWhere('product_id',$product->id)
if($collectProduct){
$collectProduct->error = $response['errMessage'];
# tpi yg ini mba bisa masuk/gabung ke collection baru?
# bisa mas, aku coba akses $collect, dia keubah errornya
# oke mba kalo gitu aman berarti
}else{
$collect->push(array(
'product_id' => $product->id,
'title' => $product->title,
'error' => $response['errMessage']
));
}
#-----------------------------------
$product->design->storePlatforms()->sync([$storePlatform->id => [ 'data' => json_encode($data)] ], false);
}
$data->where('product_id','!=', $product->id);
$data = $data->all()->map(function($messages) {
$value = $messages->first();
return array(
'product_id' => $value->product_id,
'title' => $value->title,
'error' => $value->error
);
});
}
}
$collect->map(function($messages) use ($product){
if ($messages->product_id == $product->id) {
continue;
}
return $messages;
});
$result = $collect->map(function($item, $key) use ($product){
if ($item->product_id == $product->id) {
return $item;
};
});
$result->reject(null)->toJson();
```
```json=
{
"messages": [
{
"product_id": 762,
"title": "Zipper Hoodie test profi 100",
"error": "error 1, "
},
{
"product_id": 764,
"title": "Zipper Hoodie test profi 100",
"error": "please recheck your price, profit [100] must more than"
},
{
"product_id": 763,
"title": "Zipper Hoodie test profi 100 [1,238]",
"error": "please recheck your price, profit [100] must more than"
},
{
"product_id": 765,
"title": "Zipper Hoodie test profi 100 [1,238]",
"error": "please recheck your price, profit [100] must more than"
}
]
}
"messages":{
"product_id":762,
"title":"Zipper Hoodie test profi 100",
"error":"please recheck your price, profit [100] must more than tribelio fee [1,238]"
}
}
```
1 desain => produk 1, produk 2
upload produk => 1 ->error = "salah"
desain_id | platform_id | data
1 | shopee | []