PHPackages                             kanagama/laravel-collection-deduplicate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kanagama/laravel-collection-deduplicate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kanagama/laravel-collection-deduplicate
=======================================

Collection クラスを拡張して、重複を排除する deduplicate() メソッドを追加します

v1.0.4(3y ago)044MITPHPPHP ^7.4 | ^8.0 | ^8.1 | ^8.2

Since May 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kanagama/laravel-collection-deduplicate)[ Packagist](https://packagist.org/packages/kanagama/laravel-collection-deduplicate)[ RSS](/packages/kanagama-laravel-collection-deduplicate/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (8)Used By (0)

laravel-collection-deduplicate
==============================

[](#laravel-collection-deduplicate)

機能概要
----

[](#機能概要)

php 7.4 以上 Laraevel 8.0 以上

Collection クラスの重複を削除するメソッド deduplicate() を追加します。

既存メソッド unique() と uniqueStrict()
--------------------------------

[](#既存メソッド-unique-と-uniquestrict)

コレクションの重複を排除するメソッドとして、既に [unique()](https://readouble.com/laravel/10.x/ja/collections.html#method-unique) や [uniqueStrict()](https://readouble.com/laravel/10.x/ja/collections.html#method-uniquestrict) が用意されています。この２つのメソッドは、ネストした配列やオブジェクトを取り扱いたい場合、一意であることを決めるキーを指定する必要があります。

unique(), uniqueStrict()
------------------------

[](#unique-uniquestrict)

### example

[](#example)

```
$collection = collect([
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'iPhone 5', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'Apple Watch', 'brand' => 'Apple', 'type' => 'watch'],
    ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
    ['name' => 'Galaxy Gear', 'brand' => 'Samsung', 'type' => 'watch'],
]);

// 'brand' キーで重複を判断し削除する
$unique = $collection->unique('brand');

$unique->values()->all();

/*
    [
        ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
        ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
    ]
*/
```

指定したキーの値さえ一致していれば、他のキーが一致していなくても重複として削除されてしまいます。

一意であることを決めるキーを指定するのではなく**配列の中身が完全に一致しているとかオブジェクトのプロパティや値が完全に一致しているとか**そういう場合に削除して欲しいんです…！！！！

と言いましても無いものは仕方ありませんので、そういう重複を削除できるメソッド deduplicate() メソッドをコレクションクラスに追加する拡張機能を作りました。

deduplicate() メソッド
------------------

[](#deduplicate-メソッド)

全てのキーやプロパティの値が一致していれば重複として削除します。

### example

[](#example-1)

```
$collection = collect([
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'iPhone 5', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'Apple Watch', 'brand' => 'Apple', 'type' => 'watch'],
    ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
    ['name' => 'Galaxy Gear', 'brand' => 'Samsung', 'type' => 'watch'],
    // 1つ目のキーと全く同じ配列を格納しまくる
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
]);

$deduplicate = $collection->deduplicate();

$deduplicate->values()->all();

/*
    [
        ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
        ['name' => 'iPhone 5', 'brand' => 'Apple', 'type' => 'phone'],
        ['name' => 'Apple Watch', 'brand' => 'Apple', 'type' => 'watch'],
        ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
        ['name' => 'Galaxy Gear', 'brand' => 'Samsung', 'type' => 'watch'],
        // 以降3件は1つめのキーと同じ値のため、重複として扱われ削除される
    ]
*/
```

※サンプルは配列を格納して比較していますが、格納されているのがオブジェクトでも数値でも文字列でも問題なく動作します。

使い方
---

[](#使い方)

composer でインストールするだけ。 Collection クラスに deduplicate() メソッドが追加されます。

```
composer require kanagama/laravel-collection-deduplicate
```

github
------

[](#github)

packagist
---------

[](#packagist)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

1157d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32666757?v=4)[kazuma nagama](/maintainers/k-nagama)[@k-nagama](https://github.com/k-nagama)

---

Top Contributors

[![kanagama](https://avatars.githubusercontent.com/u/80406579?v=4)](https://github.com/kanagama "kanagama (8 commits)")[![kazumacchi](https://avatars.githubusercontent.com/u/46663366?v=4)](https://github.com/kazumacchi "kazumacchi (2 commits)")

---

Tags

laravelcollectiondeduplicate

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kanagama-laravel-collection-deduplicate/health.svg)

```
[![Health](https://phpackages.com/badges/kanagama-laravel-collection-deduplicate/health.svg)](https://phpackages.com/packages/kanagama-laravel-collection-deduplicate)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2519.3k](/packages/iteks-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
