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

Prefix needed on Custom Validation Rules CP example. #1612

Open
efc opened this issue Feb 14, 2025 · 4 comments
Open

Prefix needed on Custom Validation Rules CP example. #1612

efc opened this issue Feb 14, 2025 · 4 comments

Comments

@efc
Copy link
Contributor

efc commented Feb 14, 2025

Not sure how to put in a request to fix a docs illustration, since I don't have the tools to make a new illustration.

In the Custom Validation Rules docs the illustration fails to show the App\Rules\ prefix that should go on any custom rule, even when defining it in the CP. This prefix is shown in the YAML example, but by not appearing in the CP example it strongly implies the prefix is only needed in the YAML.

Wrong, the prefix is needed in the CP as well. I just spent half an hour fumbling to learn this. It would be nice if the illustration were fixed.

Thanks!

@jasonvarga
Copy link
Member

Your rule classes can be anywhere, they don't need to be in App\Rules.

@jasonvarga
Copy link
Member

But, at least having a consistent example would be good, I agree!

@efc
Copy link
Contributor Author

efc commented Feb 14, 2025

Well, since the example starts by pointing to the Laravel docs, and the Laravel docs use php artisan make:rule and that tool puts the rule in /app/Rules, I think it would be best for the example to include the /App/Rules in the illustration. Glad you agree! :)

@efc
Copy link
Contributor Author

efc commented Feb 14, 2025

However, until right now I had not really realized this was due to the namespace and not the filesystem. It is that make:rule sets up the rule in namespace App\Rules that is the issue here, I think.

So maybe the docs could be a bit more explicit, saying something like, "don't forget to include any namespace prefix your rule may require." I imagine a lot of Statamic users are, like me, new to Laravel and not even all that familiar with concepts like namespaces. Little reminders would go a long way toward bringing us along.

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

No branches or pull requests

2 participants