laravel duplicate model code example
Example 1: laravel collection remove duplicates
$unique = $collection->unique();
Example 2: laravel eloquent duplicate record
// Retrieve the first task
$task = Task::first();
$newTask = $task->replicate();
$newTask->project_id = 16; // the new project_id
$newTask->save();
Example 3: laravel collection find duplicates
$users = Users::all();
$usersUnique = $users->unique('id');
$usersDupes = $users->diff($usersUnique);
dd($users, $usersUnique, $usersDupes);