0 => Tour {#229 ▼
#table: "tour"
#...
#attributes: array:12 [▼
"id" => 6
"name" => "Nha Trang Tour"
"price" => 3500000.0
"price_promotion" => 0.0
"id_package" => 4
"id_location" => 8
"start_time" => "2018-01-27"
"end_time" => "2018-01-28"
"star" => 4.0
"description" => "Funny"
"created_at" => null
"updated_at" => "2017-12-29 00:00:00"
]
#...
}
1 => Tour {#230 ▶}
我需要在"#items"中使用2个数组0和1中的2个id_location,我使用
($sale['items']->id_location);
和
($sale->id_location);
但不能接受,我使用
($sale[0]->id_location);
然后成功,但只得到一个
感谢您的帮助
答案 0 :(得分:1)
使用pluck()
方法(如果它是一个集合)或array_pluck
如果它是一个数组:
$sale->pluck('id_location');
array_pluck($sales, 'id_location');
答案 1 :(得分:0)