laravel remove duplicates from array code example
Example 1: laravel collection remove duplicates
$unique = $collection->unique();
Example 2: laravel remove duplicates from array
$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)
Example 3: laravel collection find duplicates
$users = Users::all();
$usersUnique = $users->unique('id');
$usersDupes = $users->diff($usersUnique);
dd($users, $usersUnique, $usersDupes);