duplicates laravel code example
Example 1: collection laravel filter
$collection = collect([1, 2, 3, 4]);
$filtered = $collection->filter(function ($value, $key) {
return $value > 2;
});
$filtered->all();
Example 2: laravel eloquent duplicate record
$task = Task::first();
$newTask = $task->replicate();
$newTask->project_id = 16;
$newTask->save();
Example 3: laravel collection find duplicates
$users = Users::all();
$usersUnique = $users->unique('id');
$usersDupes = $users->diff($usersUnique);
dd($users, $usersUnique, $usersDupes);
Example 4: laravel pluck
$users = Users::pluck('name','email');
dd($users);