Max Net Max Net - 8 months ago 92
PHP Question

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?

Answer Source

You can use the merge method:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download