So i have a Post table, where each post is in a album, i want to search by post attribute, but also bring the post's album in view, how do i do that?
i've tried using this in controller
$posts = album::whereHas('post', function($q) use ($search) {
$q->where('nama', 'like', "%$search%", 'or')->where('deskripsi', 'like', "%$search%");
})->get();
and this is my blade view to display the album first then the post
@foreach($posts as $p )
.....
@foreach($p->post->where('nama', 'like', "%$search%", 'or')->where('deskripsi', 'like', "%$search%") as $post)
....
@endforeach
@endforeach
but the problem is its giving me all the album, even the one that dont have post in it. my english is not the best but i hope you can understand it