我有3张桌子,汽车,公寓和商店。每张桌子都有它的照片。照片存储在数据库中。我只想使用一张桌子照片,我不想为每个汽车,公寓和商店创建照片列表。Laravel hasMany with Where
照片表structe是这样的;
| id | photo_url | type | destination_id |
------------------------------------------------------------
1 | http://example.com/1.jpg | Cars | 1 |
2 | http://example.com/2.jpg | Flats | 1 |
3 | http://example.com/3.jpg | Flats | 2 |
4 | http://example.com/4.jpg | Shops | 1 |
5 | http://example.com/3.jpg | Shops | 2 |
我需要在Shops,Flats和Cars模型类中定义与类型的许多关系。
这样做的正确方法是什么?
Spasibo bratan! – fobus 2014-10-17 22:24:22