$related->merge()
returns a new instance of Collection
, it doesn't modify $related
. So, the fix is simple:
foreach ($question->tags as $tag) {
if (!isset($related)) {
$related = $tag->questions;
} else {
$related = $related->merge($tag->questions);
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community