我有一个具有homeAddress的Player模型,该模型具有由外键链接的homeAddressPhoto。
我可以通过以下方式获取家庭住址照片列表:
Player::find($player_id)->homeAddress->homeAddressPhoto;
现在,我想通过homeAddressPhoto ID查找照片,但是下面的代码通过homeAddressID查找照片。
Player::find($player_id)->homeAddress->homeAddressPhoto()->where('id',$photo_id)->first();
我应该如何编写where
部分以从homeAddressPhoto而不是homeAddress获取ID?
答案 0 :(得分:0)
尝试一下:
Player::find($player_id)->homeAddress->homeAddressPhoto->where('id',$photo_id)->first();