Andreas Hunter
Andreas Hunter

Reputation: 5004

How to combine results of two query from Eloquent Model in Laravel?

I have two query to database:

$words = Word::where('word','LIKE',"%{$search}%")
               ->limit(10)
               ->get();

$words_default = DefaultWord::where('word','LIKE',"%{$search}%")
               ->limit(10)
               ->get();

How I can combine results to one var?

Upvotes: 4

Views: 6747

Answers (1)

Hedegare
Hedegare

Reputation: 2047

You can use the merge method:

$merged = $words->merge($words_default);

More info: https://laravel.com/docs/5.5/collections#method-merge

Upvotes: 3

Related Questions