Skip to content
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

Validation #69

Closed
cvhainb opened this issue Sep 30, 2019 · 7 comments
Closed

Validation #69

cvhainb opened this issue Sep 30, 2019 · 7 comments
Assignees
Labels

Comments

@cvhainb
Copy link

cvhainb commented Sep 30, 2019

Hello,

I'm a newbie inLaravel. I have tried to create a form request and add this in rules():

return $rules = [
    'translations.%name%' => 'required|string',
];

however it did not work.

This is my array:

translation.en.name
translation.de.name
translation.fr.name

So, my question is how to validate with this?

Thank you.

@Gummibeer
Copy link
Member

Hey,

you have to wrap your $rules array in the RuleFactory::make($rules);. This will replace your placeholder with all locale field combinations you have configured.

For further details please check the docs:
https://docs.astrotomic.info/laravel-translatable/package/validation-rule-factory

@Gummibeer Gummibeer self-assigned this Sep 30, 2019
@cvhainb
Copy link
Author

cvhainb commented Sep 30, 2019

Dear Gummibeer,

Thank you for replied. Yes, I have read it some times and try to learn more about laravel validation but it's not lucky for me. I'm a newbie. Is there example about this? If you have one, please send me the URL.

@Gummibeer
Copy link
Member

Instead of your current

return $rules = [
    'translations.%name%' => 'required|string',
];

you just do

return RuleFactory::make([
    'translations.%name%' => 'required|string',
]);

It will still return an array but will parse it and replace the placeholders.

@cvhainb
Copy link
Author

cvhainb commented Sep 30, 2019

You're awesome! thank you so much.

@Gummibeer
Copy link
Member

Thanks! :)
Is there anything we could improve in the docs? Writing docs as the maintainer is every time hard because I don't now which could be unknown or has to explained better with an example.

@cvhainb
Copy link
Author

cvhainb commented Sep 30, 2019

I think it's better if you have a few examples how to do that because it's more easier for newbie, like me.

I have fixed the problem. Thank you so much ^^!

@cvhainb cvhainb closed this as completed Sep 30, 2019
@turkidkil
Copy link

This is true?

< input name="translations[en][name]" > ?
Because Validation Rule did not work for me!

      $rules = [
           'translations.%name%' => ['required_without:translations.%name%', 'nullable', 'min:3', 'max:50'],
       ];

       RuleFactory::make($rules);
       $request->validate($rules);
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants