So, I was struggling to make this schema work (total newbie with laravel, by the way...) I have a 'photos' table and an audio 'tracks' table, and I want to be able to do something like this:
Track model:
// Get the photo associated with this track.
public function cover_art() {
return $this->hasOne('App\Photo');
}
Photo model:
// Get all the tracks associated with this photo.
public function tracks() {
return $this->belongsToMany('App\Track');
}
What's the best solution to represent this relationship (an audio track can have only one photo, and a photo can belong to multiple tracks)?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire