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)043MITPHPPHP ^7.4 | ^8.0 | ^8.1 | ^8.2

Since May 3Pushed 2y 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 1mo ago

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 49% 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

1105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/be317eed08600136c2e3350d92d57160b0a683957131591389d9bd42fa3b543e?d=identicon)[k-nagama](/maintainers/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

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[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.

2516.7k](/packages/iteks-laravel-enum)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[prologue/support

Prologue Support is an extension for Illuminate Support

1616.8k](/packages/prologue-support)

PHPackages © 2026

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