Done in access 2007 with all fields just see if you can convert to your needs, some field names changed, name is reserved word in access:
SELECT genres.ID, genres.gname, posts.ID, posts.genre_id, posts.gname, attachments.ID, attachments.post_id, attachments.gname, attachments.gtype
FROM (genres RIGHT JOIN posts ON genres.ID = posts.genre_id) RIGHT JOIN attachments ON posts.ID = attachments.post_id
WHERE (((genres.ID) Like "*") AND ((posts.ID) Like "*") AND ((attachments.gtype)="videomp4"))
ORDER BY posts.gname;
Joins can be tricky.
Leave out fields as needed.
So you have a defined class for every entity.
Instead of making joins, define relationships between thoose classes. A defined One-to-Many relationship in Eloquent actually builds a join query for you when you need it. Use whereHas
$genreCollection = Genre::whereHas('posts', function($postQuery){
$pstQuery->whereHas('attachments', function($attachQ){
$attachQ->where('type', '=', 'video/mp4');
}
})->get();
DB::table('models')->where...
always returns arrays. If you have a class for that table simply use
Model::where...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community