2017-11-05 2 views
2

내 Laravel 코드에서 코드의 어딘가에서 레코드를 처리 할 때 배열에 새 속성을 추가합니다 (예 : $ obj-> newAttr = someContent). 내가 객체를 dd() 할 때 #attributes와 #original이라는 두 개의 배열을 보여 주지만 새로 생성 된 속성은 #attributes 배열에만 나타난다.datt()에 대한 #attributes vs #original

#attributes: array:21 [▼ 
"field_name" => "229" 
"company_name" => "Maya Dairy" 
"seeding_rate" => 115 
"id" => 11 
"property_id" => 71 
"acreage" => "73.80" 
"status" => "current" 
"dairy_crop_variety_id" => 19 
"field_weight" => "1432.39" 
"moisture" => "67.00" 
"starch" => null 
"yield_id" => 50 
"crop" => "Wheat: <strong>Sumit 515</strong> @ <strong>21.3 T/c</strong>" 
"variety" => "Sumit 515" 
"planted_at" => "Nov 10, 2016" 
"harvested_at" => "May 1, 2017" 
"crop_age" => 172 
"cropDateLink" => "Harvested: <a href="#" data-toggle="modal" data-target="#editRowCrop" data-id="11" data-method="PATCH"><strong>May 1, 2017</strong> (172 days)</a>" 
"yield" => 21.3 
"inputs" => "" 
"files" => "" 

원래 배열 :

#original: array:16 [▼ 
"field_name" => "229" 
"company_name" => "Maya Dairy" 
"seeding_rate" => 115 
"id" => 11 
"property_id" => 71 
"acreage" => "73.80" 
"status" => "current" 
"dairy_crop_variety_id" => 19 
"field_weight" => "1432.39" 
"moisture" => "67.00" 
"starch" => null 
"yield_id" => 50 
"crop" => "Wheat" 
"variety" => "Sumit 515" 
"planted_at" => "2016-11-10" 
"harvested_at" => "2017-05-01" 

이 배열의 차이는 무엇 I는() 객체를 위해 dd 때 여기

는 I가 #attributes 어레이를 얻는 예이다? 때로는 새로 생성 된 속성을보기에 사용할 수없는 경우가 있습니다. 왜 그런지 모르겠습니다. 모든 제안은 높이 평가됩니다.

+0

원본은 컨트롤러에서 변경하기 전에 모델의 원본 데이터를 의미합니다. – spirit

답변

5

$에는 현재 버전의 모델 속성이 포함되어 있습니다. $ 원본에는 주어진 객체의 원래 값이 포함되어 있다고 가정하므로 여기에는 객체가 생성 된 값이나 데이터베이스에서로드 된 값을 찾을 수 있습니다.

참고 :$ 원래 값이 데이터베이스에 모델을 저장하면 새 값으로 업데이트 할 수있을만큼 영리하다 - 아이디어는이 배열 데이터베이스에 오브젝트의 데이터를 반영해야한다는 것입니다.