php - Laravel Eloquent Multiple Join -


i have table albums, each album has multiple songs, artworks, , can belong number of series.

each of songs can have lyrics table.

so far have :

routes.php

    route::get('get_albums', function() {         return album::with('songs', 'artworks', 'series')->get();       }); 

album.php model

<?php  class album extends eloquent {      protected $table = 'albums';      public function songs()     {         return $this->hasmany('song');     }       public function artworks()     {         return $this->hasmany('artwork');     }      public function series()     {         return $this->hasmany('serie');     }     } 

song.php model

<?php  class song extends eloquent {     public function album()     {         return $this->belongsto('album');     }      public function lyric() {         return $this->hasone('lyric');     }  } 

artwork.php model

<?php  class artwork extends eloquent  {      public function album()     {         return $this->belongsto('album');     }  } 

serie.php model

<?php  class serie extends eloquent {     public function album()     {         return $this->belongsto('album');     }  } 

lyric.php model

<?php  class lyric extends eloquent {     public function song()     {         return $this->belongsto('song');     } } 

this gives me albums songs, artworks, , series. trying figure out how 2nd join lyrics songs.

you can try

route::get('get_albums', function() {     return album::with('songs.lyric', 'artworks', 'series')->get();   }); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -