How to Merge Two Eloquent Collections?

The merge method returns the merged collection, it doesn’t mutate the original collection, thus you need to do the following $original = new Collection([‘foo’]); $latest = new Collection([‘bar’]); $merged = $original->merge($latest); // Contains foo and bar. Applying the example to your code $related = new Collection(); foreach ($question->tags as $tag) { $related = $related->merge($tag->questions); }

Eloquent Collection: Counting and Detect Empty

When using ->get() you cannot simply use any of the below: if (empty($result)) { } if (!$result) { } if ($result) { } Because if you dd($result); you’ll notice an instance of Illuminate\Support\Collection is always returned, even when there are no results. Essentially what you’re checking is $a = new stdClass; if ($a) { … … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)