I have four tables: characters, pets, characters_pets and characters_pets_metadata. A character has many pets on the pivot table characters_pets, but I also need to get the data from the metadata table:
class Character extends Model {
protected $table = 'characters';
public function pets() {
retu $this->belongsToMany('Pet', 'characters_pets');
}
}
class CharacterPet extends Model {
protected $table = 'characters_pets';
public function metadata() {
retu $this->hasMany('PetMetadata');
}
}
How can I fetch the metadata for each character through a relationship?
