Not allow identic records
How do i not allow user to create records with the same values of existing ones
exemple:
brand_id->1
model_id->2
i cant pass ->unique() to each field because that would only allow to have one of each
3 Replies
you mean, the user cannot create a record with brand_id 1 and model_id 1 if it already exists on the database?
but he can create lets say brand_id 1 and model_id 2 ?
exacly that
your case its a bit diff from the other post
you need a unique based on two columns
in your migration, add
$table->unique(['brand_id', 'model_id'])
and on your resource, create a custom rule
https://filamentphp.com/docs/3.x/forms/validation#custom-rules
https://laraveldaily.com/post/laravel-unique-validation-multiple-columns