-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
[Feature] Different rules per locale #70
[Feature] Different rules per locale #70
Conversation
2eb4040
to
0743de5
Compare
038e263
to
c4eedbc
Compare
Hello again, can I perhaps have a reply on this, if this is a feature with merge potential? |
Very nice, could you also update the readme with an example on how to use this? |
@freekmurze Absolutely. I'll do it tomorrow, after Easter is over. Cheers! |
@freekmurze I added it. I also added the |
fe0efa6
to
072875d
Compare
Rebased with main |
The tests fail because of Nova installation issues, but I'm willing to merge already if you already tested in manually and can confirm that it works as intended. |
Thank you! |
Hello,
first time pull-requester here in the environment of Spatie. I'm hoping to get a feature in that I personally could use in one of my projects.
So, we have various translatable models, and of course our editors work in a Nova panel to edit and create them. The particular case we have is about news articles. The main language of our website is English, but we also publish in German and French.
In our workflow, an author will get to work writing and Article in English, and then publish it. After that is done he or she will begin translating the article to the other languages.
Currently we do not use any rules on our fields for news articles, because if we would set the title to required, it would require a title in English, German and French. But we only want the English title to be required, and the translations optional.
This pull request aims to solve this problem.
It contains six new public methods that can be called on the Translatable fields:
rules(array $rules)
The rules method will take a nested array of field names, which then in turn contain a key-value pair of a locale and its rules. For example:
rulesFor(string $field, string $locale, $rules)
A more dynamic method to declare rules per field. A syntax I personally find a little more elegant and readable. It achieves the same behaviour like so:
In addition to those two, there are also methods for creation rules and update rules.
Of course, all methods work with all three types of Laravel rules declaration (string, array and Rule classes).
That's it from me. Any feedback is greatly appreciated.
Resolves: #64