-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
i would like to propose the inclusion of diffing of Eloquent collections. This feature could be useful in belongsToMany
relationships, for example if a blog Post
belonged to many Categories
, you could find the categories it doesn't belong to by diffing the collections.
My proposed implementation is below and I have a branch ready with tests to make a pull request if this is accepted.
public function diff(Collection $collection)
{
$diff = new static;
foreach ($this->items as $item)
{
if ( ! $collection->contains($item->getKey()))
{
$diff->add($item);
}
}
return $diff;
}
Metadata
Metadata
Assignees
Labels
No labels