我在模型中的关系如下:
class HotelBooking extends Model
{
public function rooms(){
return $this->belongsToMany('App\Room', 'hotelbooking_room', 'hotelbooking_id')->withPivot(['quantity', 'addon_id']);
}
}
当我致电$booking->rooms()->get();
时,我应该获得以下数据:
"rooms": [
{
"id": 28,
"hotel_id": 89,
"type": "Double",
"quantity": 4,
"adults": 2,
"children": 1,
"description": null,
"created_at": "2016-05-15 12:24:39",
"updated_at": "2016-05-15 15:29:58",
"pivot": {
"hotelbooking_id": 30,
"room_id": 28,
"quantity": 1,
"addon_id": 386
}
}
]
这通常是正确的。有点奇怪的是,当我向电子邮件数据发送$rooms
时,不会发送pivot
属性。它在网站上运行良好,但如果在电子邮件中发送它不会。知道为什么吗?!