F
Filament4mo ago
ericmp

`TextInput` `distinct` v3 equivalent in v2?

In v3 i do:
TextInput::make('name')
->required()
->distinct()
TextInput::make('name')
->required()
->distinct()
Now i have to do it also in a v2 project, but idk how to. which would be the equivalent?
TextInput::make('name')
->required()
// ->distinct() (method doesn't exist in v2)
TextInput::make('name')
->required()
// ->distinct() (method doesn't exist in v2)
2 Replies
Tieme
Tieme4mo ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
ericmp
ericmp4mo ago
thankss crazy, but this way seems it works
->rules([
function () {
return function (string $attribute, $value, \Closure $fail) {
$explodedDotNotationPath = explode('.', $attribute);

$field = $this->mountedTableActionData['fields'][$explodedDotNotationPath[2]];

$fieldOptionNames = collect($field['options'])->pluck('name')->toArray();

$count = array_count_values($fieldOptionNames)[$value] ?? 0;

$isNotUnique = $count > 1;

if ($isNotUnique) {
$fail(__('The name must be unique'));
}
};
},
])
->rules([
function () {
return function (string $attribute, $value, \Closure $fail) {
$explodedDotNotationPath = explode('.', $attribute);

$field = $this->mountedTableActionData['fields'][$explodedDotNotationPath[2]];

$fieldOptionNames = collect($field['options'])->pluck('name')->toArray();

$count = array_count_values($fieldOptionNames)[$value] ?? 0;

$isNotUnique = $count > 1;

if ($isNotUnique) {
$fail(__('The name must be unique'));
}
};
},
])
what do u think xd? im overcomplicating it, or u would do the same aprox? its inside a repeater, that's why i just dont do: rules(['distinct']), since wont actually checks it
Want results from more Discord servers?
Add your server
More Posts