mercredi 19 février 2020

Get data from multiple table in Laravel 5.7 (Eloquent)

I am using Laravel 5.7. I have three MySQL table, named : movies, directors, actors. I am having issues with retrieving data from these tables. Look at my table structure:

movies
|-----------------------------------------------------|
|   id  |   title       |   release |  img_url        |
|-----------------------------------------------------|
|  1    |  Avengers     |    2019   |    #            |
|-----------------------------------------------------|
|  2    |  Avatar       |    2009   |    #            |
|-----------------------------------------------------|
|  3    |  Titanic      |    1997   |    #            |
|-----------------------------------------------------|

directors
|-----------------------------------------------------|
|   id  |   movie_id  |   dir_name      |  add_date   |
|-----------------------------------------------------|
|  1    |    1        |  Anthony Russo  |  2019/02/18 |
|-----------------------------------------------------|
|  2    |    1        |    Joe Russo    |  2019/02/18 |
|-----------------------------------------------------|
|  3    |    2        |    Cameron      |  2019/02/18 |
|-----------------------------------------------------|

actors
|-----------------------------------------------------|
|   id  |   movie_id  |   act_name      |  add_date   |
|-----------------------------------------------------|
|  1    |    1        |  Robert Downey  |  2019/02/18 |
|-----------------------------------------------------|
|  2    |    1        |   Chris Evans   |  2019/02/18 |
|-----------------------------------------------------|
|  3    |    1        |  Mark Ruffalo   |  2019/02/18 |
|-----------------------------------------------------|
|  4    |    1        |   Chris Pratt   |  2019/02/18 |
|-----------------------------------------------------|
|  5    |    2        |   Worthington   |  2019/02/18 |
|-----------------------------------------------------|
|  6    |    2        |    Weaver       |  2019/02/18 |
|-----------------------------------------------------|
|  7    |    2        |    Saldana      |  2019/02/18 |
|-----------------------------------------------------|

I Want
|-------------------------------------------------------------------------------------------------------------------------------------------|
|   id  |   title       |   release |  img_url    |        directors           |                        actors                              |
|-------------------------------------------------------------------------------------------------------------------------------------------|
|  1    |  Avengers     |    2019   |    #        | Anthony Russo, Joe Russo   |  Robert Downey, Chris Evans, Mark Ruffalo, Chris Pratt     | 
|-------------------------------------------------------------------------------------------------------------------------------------------|
|  2    |  Avatar       |    2009   |    #        |     Cameron                |  Worthington, Weaver, Saldana                              |
|-------------------------------------------------------------------------------------------------------------------------------------------|
|  3    |  Titanic      |    1997   |    #        |                            |                                
|-------------------------------------------------------------------------------------------------------------------------------------------|

Look at the table 'I want' at the bottom of the code. This is what is want. Please don't attach the link below as proof of already answered. It doesn't match with my requirement
how to retrive data from multiple table in laravel eloquent



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bPLMfl
via IFTTT

1 commentaire:

  1. Use this diet hack to drop 2 lb of fat in just 8 hours

    More than 160 thousand men and women are utilizing a simple and secret "liquid hack" to lose 2lbs each and every night in their sleep.

    It's effective and works with anybody.

    Here's how you can do it yourself:

    1) Go get a glass and fill it with water half full

    2) Then do this proven hack

    so you'll become 2lbs skinnier as soon as tomorrow!

    RépondreSupprimer