Jefry
How to validate two fields combined are unique
i got it to work like this
TextInput::make('name')->label('Nombre')->required()->rules([
fn (Get $get, string $operation, ?Model $record): Closure => function (string $attribute, $value, Closure $fail) use ($get, $operation, $record) {
if ($operation === 'create') {
$exists = Product::where('name', $get('name'))->where('size_id', $get('size_id'))->exists();
if ($exists) {
$fail('Ya existe un producto con este nombre y tamaño.');
}
}
if ($operation === 'edit') {
$exists = Product::where('name', $get('name'))
->where('size_id', $get('size_id'))
->where('id', '!=', $record->id)->exists();
if ($exists) {
$fail('Ya existe un producto con este nombre y tamaño.');
}
}
}
])
in case anybody might need it7 replies