이미 stackoverflow 에서이 문제에 대한 몇 가지 질문을 읽었으며 해당 답변 중 어느 것도 나에게 적용되지 않습니다. 내가 실행할 때 :
$item_price = ItemPrice::where('item_name',$itemname)->first();
그리고
$item_price->price
비 객체의 속성을 얻으 려고 시도 하지만 실행할 때 :
dd($item_price = ItemPrice::where('item_name',$itemname)->first());
이름, 가격 등의 속성을 가진 객체를 반환하고 있습니다. 여기서 무슨 일이 일어나고 있는지 정말 이해하지 못합니다.
전체 코드 :
foreach ($inventorydecoded->assets as $asset) {
$i = 0;
$a = 0;
while ($a < 1) {
if ($inventorydecoded->descriptions[$i]->classid == $asset->classid) {
$a = 1;
$classid = $inventorydecoded->descriptions[$i]->classid;
$itemname = $inventorydecoded->descriptions[$i]->market_hash_name;
$tradable = $inventorydecoded->descriptions[$i]->tradable;
$name_color = $inventorydecoded->descriptions[$i]->name_color;
;
}
$i++;
} // end of while
if ($tradable === 1 && strpos_arr($itemname, $blacklist) == false ) {
$item_price = ItemPrice::whereItemName($itemname)->first();
// dd(ItemPrice::where('item_name',$itemname)->first());
$items[] = ['assetid' => $asset->assetid,'classid'=> $classid,'itemname'=>$itemname,'name_color'=>$name_color,'price'=> $item_price->price];
$serialized_inventory = serialize($items);
}
} // end of foreach
이 쿼리를 루프에서 사용하고 있으므로 그중 하나가 비어 있고 null
. 따라서 간단한 확인이 필요합니다.
if (is_null($item_price)) {
// There is no price for this item, do something.
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다