-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filament support #25
Comments
Hi, I'm not familiar with Filament. It seems that the built-in https://filamentphp.com/docs/2.x/forms/validation#unique
When you look at the code, it evaluates the parameters and generates a standard What I don't see is a nice way to add more rules, except with the |
I tried to investigate using the simple way similar to Laravel Nova. Forms\Components\TextInput::make('slug')->required()
->rules(['unique_translation:posts,slug']), It doesn't generate any error but it allows the duplication. After a quick check, I noticed that the generated query is wrong. It is generating the name of the column in place of the code of language. Actual generated query (not working) select count(*) as aggregate from `posts` where (`slug` LIKE %"slug": "books"% or `slug` LIKE %"slug":"books"%)) Excpected query select count(*) as aggregate from `posts` where (`slug` LIKE %"en": "books"% or `slug` LIKE %"en":"books"%)) I found the source of this issue and a solution. It is related to the function Actual protected function getArrayAttributeNameAndLocale($attribute)
{
return $this->getAttributeNameAndLocale($attribute, '.');
} Working protected function getArrayAttributeNameAndLocale($attribute)
{
return $this->getAttributeNameAndLocale($attribute, ',');
} |
When I change the dot to a comma my validation tests fail. Illuminate\Database\Events\QueryExecuted^ {
+sql: "select count(*) as aggregate from `test_models` where (`slug` LIKE ? or `slug` LIKE ?)"
+bindings: array:2 [
0 => "%"en": "existing-slug-en"%"
1 => "%"en":"existing-slug-en"%"
]
+time: 0.28
+connection: Illuminate\Database\MySqlConnection^ {#940 …24}
+connectionName: "mysql"
} The dot is what Laravel uses to notate array fields in the form. <!-- This assumes you want to use the current locale -->
<input name="slug">
<!-- Specific locales in array syntax -->
<input name="slug[en]">
<input name="slug[nl]"> Can you show me in what format the form input is received? I think this trait handles the validation: |
Hi, I found this: Does that help? |
I fixed on my side: #26 |
Thank you for the PR! 👍 |
Hello,
I tried to use this great package with Filament which handles translations using spatie/nova-translatable in a simple way like Laravel Nova, unfortunately this is not working (allowing duplication).
Laravel Nova
Filament (assumed and tested)
Thanks.
The text was updated successfully, but these errors were encountered: