Skip to content

Conversation

@techmahedy
Copy link
Member

@techmahedy techmahedy commented Jan 22, 2026

duplicate usages example

// Find duplicate emails
$users = User::all();
$duplicateEmails = $users->duplicates('email');

if ($duplicateEmails->isNotEmpty()) {
    Log::warning("Found duplicate emails", $duplicateEmails->all());
}

// Find duplicate orders
$orders = Order::all();
$duplicateOrders = $orders->duplicates('transaction_id');

// Simple duplicates
$numbers = new Collection(Model::class, [1, 2, 2, 3, 3, 3, 4]);
$dupes = $numbers->duplicates(); // [2, 3, 3] (all but first occurrence)

sole example

Get exactly one item or throw an exception

// Get user by unique email
try {
    $user = User::all()->sole(fn($u) => $u['email'] === 'admin@example.com');
} catch (\RuntimeException $e) {
    // Either no user found or multiple users found
    Log::error($e->getMessage());
}

pipe example

Execute a callback without modifying the collection

$csv = $users->pipe(function($collection) {
    return $collection
        ->map(fn($u) => implode(',', $u))
        ->implode("\n");
});

@techmahedy techmahedy merged commit d83b4f5 into doppar:3.x Jan 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant