geetpurwar
1 year ago

Merge Returning Empty Collection

Posted 1 year ago by geetpurwar

hi, I am using collection merge method and its returning empty collection. How do I correctly use it?

use Illuminate\Database\Eloquent\Collection;

$final = new Collection();
    
$first_collection = Notification::where('id', 1)->get();
$second_collection = Notification::where('id', 2)->get();

$final->merge(first_collection);
$final->merge($second_collection);

dd($final);

Result:

Collection {#358 ▼
  #items: []
}

Please sign in or create an account to participate in this conversation.