docs icon indicating copy to clipboard operation
docs copied to clipboard

Prefix needed on Custom Validation Rules CP example.

Open efc opened this issue 10 months ago • 4 comments

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!

efc avatar Feb 14 '25 17:02 efc

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

jasonvarga avatar Feb 14 '25 17:02 jasonvarga

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

jasonvarga avatar Feb 14 '25 17:02 jasonvarga

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 avatar Feb 14 '25 19:02 efc

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.

efc avatar Feb 14 '25 19:02 efc