jarektkaczyk / eloquence-validable

Eloquence Validable extension for Eloquent ORM
MIT License
24 stars 17 forks source link

Support the creation of rules through generateXxxxRules() methods #8

Open jpvaillancourt opened 2 years ago

jpvaillancourt commented 2 years ago

I had an issue while using the $xxxRules properties since they cannot contains methods in their declaration. And considering that some validators can be created through the Illuminate\Validation\Rule class to be given some more parameters, I had to support some sort of a method to generate rules.

This pull request adds the support to methods with the naming generateXxxxRules(), without modifying the core.

Example :

protected static function generateDynamicRules() {
    return [
        'crew_code' => Rule::unique('App\Models\User')->where('active', 1),
    ];
}

This PR was tested in context and added to the unit testing.