2016-10-21 16 views

答えて

3

コレクションをお持ちの場合はpushまたはputメソッドを使用できます。プットと

例:

$collection = collect(['product_id' => 1, 'name' => 'Desk']); 

$collection->put('test', 'test'); 

$collection->all(); 

出力は次のようになりますプッシュと

['product_id' => 1, 'name' => 'Desk', 'test' => 'test'] 

例:

$collection = collect([1, 2, 3, 4]); 

$collection->push(5); 

$collection->all(); 

出力:

[1, 2, 3, 4, 5] 

リファレンス:https://laravel.com/docs/5.3/collections#method-push

0

を持っていない私は$pro->sig()の出力を印刷するとき

foreach ($pro->sig()->get() as $key => $sig) { 
      $sig->val = 2; 
     } 

を、私は次のように試してみました

foreach ($user->emails as $key => $email) { 
    $email->test = "test"; 
} 
return $user->emails; 

それはのような出力以下、

{ 
    "id": 76, 
    "user_id": 5, 
    "additional_email": "[email protected]", 
    "test": "test" 
    } 

このようにしてください。

関連する問題