F
Filament8mo ago
Wbzy

Halt doesnt stop the editing proccess?

so i have a simple edit action i want to do Unique Validation for Multiple Columns a product cant have the same type, brand and category. when im using the halt(), the record still updated somehow
->mutateFormDataUsing(function (array $data): array {
$type = ProductType::find($data['product_type_id']);
$brand = ProductBrand::find($data['product_brand_id']);
$category = ProductCategory::find($data['product_category_id']);

$data['name'] = $type->name . ' ' . $brand->name . ' - ' . $category->name;

return $data;
})
->before(function(EditAction $action, Product $record, array $data){
$product = Product::where('name', $data['name'])
->whereNotIn('id', [$record->id])
->exists();

if($product){
Notification::make()
->title('Data should be unique')
->danger()
->seconds(5)
->send();

$action->halt();
}
}),
->mutateFormDataUsing(function (array $data): array {
$type = ProductType::find($data['product_type_id']);
$brand = ProductBrand::find($data['product_brand_id']);
$category = ProductCategory::find($data['product_category_id']);

$data['name'] = $type->name . ' ' . $brand->name . ' - ' . $category->name;

return $data;
})
->before(function(EditAction $action, Product $record, array $data){
$product = Product::where('name', $data['name'])
->whereNotIn('id', [$record->id])
->exists();

if($product){
Notification::make()
->title('Data should be unique')
->danger()
->seconds(5)
->send();

$action->halt();
}
}),
3 Replies
toeknee
toeknee8mo ago
you use halt on validation, so you need a custom validation rule, opposed to using ->before() then you can prevent non-unique data being saved opposed to on loading
Wbzy
Wbzy8mo ago
can you show me an example to make a Unique Validation for Multiple Columns in filament?
toeknee
toeknee8mo ago
Sorry is this using the form or tables view? I would assume it would be part of the form to prevent that data being saved