I am using Laravel 5.1.
I have Three Table.
- Films
- Videos
- Video Category
User can create a film and add many videos, but every video should belong to any one category (example. Making Video, Trailer Video, Film Events).
Now i want to fetch all films,video and video category of each video by passing a Film ID.
Table structure
Films Table
filmID | filmName
-----------------
1 | Film 1
2 | Film 2
Video Table
videoID | catID | videoURL
--------------------------
1 | cat1 | URL 1
2 | cat2 | URL 2
Video Category Table
catID | category
--------------------
cat1 | Trailer
cat2 | Making
cat3 | Events
I can get All the Videos by passing FilmID
{
filmId: "filmName",
filmName: "Film Name",
coverPhoto: "image URL",
created_at: "2015-06-28 06:35:26",
updated_at: "2015-06-28 06:35:45",
videos: [
{
id: 7,
filmId: "filmID",
videoCategory: "trailer",
videoUrl: "h41Jb29P4",
created_at: "2015-06-28 11:40:22",
updated_at: "2015-06-28 11:40:22"
}
]
}
But how to i get the Video Category along with this output. Something like this
{
filmId: "filmName",
filmName: "Film Name",
coverPhoto: "image URL",
created_at: "2015-06-28 06:35:26",
updated_at: "2015-06-28 06:35:45",
videos: [
{
id: 7,
filmId: "filmID",
videoCategory: "trailer",
videoUrl: "h41Jb29P4",
created_at: "2015-06-28 11:40:22",
updated_at: "2015-06-28 11:40:22"
videoCategory: [
{
videoCategoryId: "1",
videoCategoryName: "Trailer"
}
]
}
]
}
Is there any way to do without passing multiple queries and merge in PHP?
Please anyone Help me.
Aucun commentaire:
Enregistrer un commentaire