私はループをいくつかのjson値を設定しています。追加しようとした表示名のイムは、ここで私のダンプでlaravel set属性がjsonキーに追加されない
$product->attributes['display_name'] = $field->display_name;
である私は、この
"id":"20",
"display_name":"Size",
"customfields":[
{
"id":"1",
"product_id":"20",
"store_id":null,
"custom_field_id":"1",
"value":"RED",
"created_at":"2016-09-14 09:32:00",
"updated_at":"2016-09-14 09:32:14"
},
としてJSONを見ることができます
if (isset($product->customfields)) {
foreach ($product->customfields as $customfield) {
$fieldId = $customfield['custom_field_id'];
// Grab custom field template code
$field = CustomField::find($fieldId);
$product->attributes['display_name'] = $field->display_name;
}
}
しかし、私はのいずれかに変更しようとすると、この
$product->attributes['customfields']['display_name'] = $field->display_name;
$product->attributes['customfields'] = $field->display_name;
私はちょうどこれを得る
"id":"20",
"customfields":[
{
"id":"1",
"product_id":"20",
"store_id":null,
"custom_field_id":"1",
"value":"RED",
"created_at":"2016-09-14 09:32:00",
"updated_at":"2016-09-14 09:32:14"
},
カスタムフィールドのキーに追加する属性を設定するにはどうすればよいですか?
編集:
おかげで
を示唆するために@Manishする完全なファイル$製品 - > customfields - [ 'DISPLAY_NAME'] = $フィールド - > DISPLAY_NAME。今"customfields":{
"0":{
"id":"1",
"product_id":"10000",
"store_id":null,
"custom_field_id":"1",
"value":"RED",
"created_at":"2016-09-14 09:32:00",
"updated_at":"2016-09-14 09:32:14"
},
"1":{
"id":"2",
"product_id":"10000",
"store_id":null,
"custom_field_id":"2",
"value":"",
"created_at":"2016-09-14 10:22:14",
"updated_at":"2016-09-14 10:22:14"
},
"display_name":"Size"
},
を返しますが、カスタム表示名にサイズと色を持つ2つのフィールドがある
。私はおそらく、新しいループを作成し、display_nameをループする必要があると思う。この場合は助言してください。代わりにこれを行います。
'Eloquent \ Model'クラスの' attributes'プロパティが保護されているので、実際にはうまく動作します。あなたは '過負荷のプロパティの間接的な変更'やそれに類するものを得るべきです。あなたはそのコードの中で何の誤りもないと確信していますか? – Skysplit
エラーはオンです。しかし、私はOcotberCMSを使用しているので、多分実際には上記のコードと関係があります。 – ServerSideSkittles
確かに。 OctoberCMSはプロパティの可視性を変更しますhttps://github.com/octobercms/library/blob/master/src/Database/Model.php#L48 – Skysplit