I've inherited 4 MySQL tables:
listings
-id
-description
...
locations
-id
-listing_id
guides
-id
-name
....
guide_location
-id
-guide_id
-location_id
Listing=>(many) Locations
Guide=>(many) Locations=>(1) Listing
Listing, Location and Guide each is its own model in a Laravel Dingo application. Here's the setup:
//Listing model
public function locations()
{
return $this->hasMany('Location');
}
Then
//Location model
public function guides()
{
return $this->belongsToMany('Guide');
}
public function listing()
{
return $this->belongsTo('Listing');
}
And
//Guide model
public function locations()
{
return $this->belongsToMany('Location');
}
I've added a column to guide_location and I want to return it when I select a Guide from the database.
So now:
guide_location
-id
-guide_id
-location_id
-position
I tried adding ->withPivot('position')
to both belongsToMany()
statements in the Guide and Location models but it's not working, I'm not seeing the new column.
Any ideas what I'm doing wrong?