Hey there, I'm trying to remove a nested item from a collection using the reject method, but i couldn't get it done, don't know why, here's the code:
$threads = collect([
[
'id' => 1, 'subject' => 2, 'participants' => collect([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'Doe'],
])
],
[
'id' => 2, 'subject' => 4, 'participants' => collect([
['id' => 4, 'name' => 'Foo'],
['id' => 2, 'name' => 'Doe'],
])
],
]);
$filtered = $threads->each->participants->reject(function ($participant) {
return $participant->id === 2;
});
Thank you for your assistance!