Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想显示与表有关系status的表中的字段值。当我执行此代码时:boardingstravel
status
boardings
travel
$travel->boardings->status
它返回一个错误,说$status是未定义的。
$status
如您所见boardings,它是 Collection 类型,因此您可以将其与索引一起使用
$travel->boardings[0]->status
或使用 for 循环
foreach($travel->boardings as $boarding){ $status = $boarding->status; }