I need some help to find out a best way to fetch data from following table structure.
Table One: organisations id name etc.
Table Two: locations id name etc.
Table Three: organisaiton_locations this table holds the relation as follows:
id | organisation_id | location_id
- id: auto-increment
- organisation_id foreign key reference to id on organisations table
- location_id foreign key reference to id on locations table
Whey I try this with hasManyThrough, I get the correct number of items but they are mapped to id instead of location_id.
class Organisation extends Model
{
public function locations()
{
return $this->hasManyThrough('App\Models\Location', 'App\Models\OrganisationLocation', 'organisation_id', 'id');
}
}
Can you please help me understand how can I fetch all locations related to an organisation in a collection so that can be used in a transformer.
Thanks in advance.