2 months ago

Laravel Nova and Showing Has Many of a Has Many Resource

Posted 2 months ago by billythekidd

Hi guys,

Ok I have 4 tables. companies, contacts, company_contact, and domains.

Companies and Contacts and Many to Many - hence the pivot table.

A company owns one domain so in the companies table, a field exists - domain_id.

So what I want to do in NOVA

Look up a contact On the view screen, See their related companies appear as a sortable table (working) See the domains related to ANY of these companies appear in a seperate table (not working)

Not sure what I am doing wrong.

No trouble to go the other way around - eg I can

Look up a company See related contacts See related domains

But just not the other way around!

Driving me nuts. Have tried a HasManyThrough relationship to no avail, tried making a model/resource of the pivot table, should be as easy as just a simple method in the Contact class saying: return $this->company()->get()->domains(); But doesn't like that at all cause its not returning a collection.

Please help!


Please sign in or create an account to participate in this conversation.