Laravel - Collections - Method Duplicates

The duplicates method retrieves and returns duplicate values from the collection:

    
    $collection = collect(['a', 'b', 'a', 'c', 'b']);
    
    $collection->duplicates();
    
    // [2 => 'a', 4 => 'b']
	

If the collection contains arrays or objects, you can pass the key of the attributes that you wish to check for duplicate values:

    
    $employees = collect([
        ['email' => '[email protected]', 'position' => 'Developer'],
        ['email' => '[email protected]', 'position' => 'Designer'],
        ['email' => '[email protected]', 'position' => 'Developer'],
    ]);
    
    $employees->duplicates('position');
    
    // [2 => 'Developer']