У меня есть следующие таблицы:
contacts(id, name, email, phone_no)
,
events(id, title, start_date, end_date)
,
addresses(id, city, state, country, zip_code)
addressables(id, address_id, addressable_id, addressable_type)
Здесь addressables
имеет много-много полиморфных отношений для contacts
events
. addressables
также может содержать другой класс полиморфных моделей.
Адрес Модель
public function addressable()
{
return $this->morphTo();
}
Событие / Модель контакта
public function addresses()
{
return $this->morphToMany(Address::class, 'addressable');
}
Я хотел получить адреса вместе с соответствующими моделями. Буду признателен, если кто-нибудь поможет мне
- Список адресов с соответствующими моделями
- Список адресов для определенного типа модели
- Список групп адресов по типу модели
ОБНОВЛЕНО
Ожидаемые результаты:
адрес
id | address
1 | New York, USA
2 | California, USA
3 | Nevada, USA
контакты
id | name
1 | Albert King
2 | Michelle Johnson
3 | Sujit Baniya
События
id | title
1 | Event 1
2 | Event 2
3 | Event 3
addressables
id | address_id | addressable_id | addressable_type
1 | 1 | 1 | Contact
2 | 2 | 1 | Event
3 | 3 | 2 | Contact
ИСКЛЮЧЕННЫЙ РЕЗУЛЬТАТ для Address :: with ('addressables')
Address - ID 1
----Details (New York, USA)
----Contact (Albert King)
Address - ID 2
----Details (California, USA)
----Event (Event 1)
Address - ID 3
----Details (Nevada, USA)
----Contact (Michelle Johnson)
Заранее спасибо!