$media->whereHas('post_picture',function($q) use($media_type) { $q->where('picture_type', $media_type); }); // whereHas