Codes Index
<?php
use Illuminate\Support\Facades\Validator;
$usernames = [
['username' => 'tonystark'],
['username' => 'brucebanner'],
['username' => 'thor'],
['username' => 'tonystark'], // Duplicate value
];
// Instead of this
$filteredCount = collect($usernames)->unique('username');
$result = $filteredCount->count() !== collect($usernames)->count();
// Use this
Validator::make($usernames, ['*.username' => 'distinct:strict'])->fails();