You need the "belongsToMany" relationship.
public function companies() {
return $this->belongsToMany('ExCompany', 'companies_groups', 'company_id', 'group_id');
}
I'm not sure from the top of my head if the order of the keys (company_id and group_id) is correct, maybe you will need to switch them.
HI ftiersch.
I had a problem with connecting to the wrong instance of a database so I was not getting the results I was expecting so the many to many set-up didn't appear to be working.
When I start by obtaining a single group first and then getting the companies, I end up with a unique set of companies. I have a problem when I try and select multiple groups first and then get the companies afterwards I end up with a collection of groups and doing groups->companies does not seem to work.
How can I obtain a unique set of companies in one collection by any number of groups they belong in?
Thanks
Edit : I found what i needed here.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community