@@ 212-225 (lines=14) @@ | ||
209 | * @param \ArrayAccess|array $items |
|
210 | * @return static |
|
211 | */ |
|
212 | public function diff($items) |
|
213 | { |
|
214 | $diff = new static([], $this->model); |
|
215 | ||
216 | $dictionary = $this->getDictionary($items); |
|
217 | ||
218 | foreach ($this->items as $item) { |
|
219 | if (!isset($dictionary[(string) $item->getKey()])) { |
|
220 | $diff->add($item); |
|
221 | } |
|
222 | } |
|
223 | ||
224 | return $diff; |
|
225 | } |
|
226 | ||
227 | /** |
|
228 | * Intersect the collection with the given items. |
|
@@ 233-246 (lines=14) @@ | ||
230 | * @param \ArrayAccess|array $items |
|
231 | * @return static |
|
232 | */ |
|
233 | public function intersect($items) |
|
234 | { |
|
235 | $intersect = new static([], $this->model); |
|
236 | ||
237 | $dictionary = $this->getDictionary($items); |
|
238 | ||
239 | foreach ($this->items as $item) { |
|
240 | if (isset($dictionary[(string) $item->getKey()])) { |
|
241 | $intersect->add($item); |
|
242 | } |
|
243 | } |
|
244 | ||
245 | return $intersect; |
|
246 | } |
|
247 | ||
248 | /** |
|
249 | * Return only unique items from the collection. |