dwightwatson / validating

Automatically validating Eloquent models for Laravel
MIT License
968 stars 76 forks source link

Objects or closures in rules unsupported #200

Closed Propaganistas closed 6 years ago

Propaganistas commented 6 years ago

Hi

A rather important heads up: according to the official docs Laravel also supports Rule objects and closures in a rules array:

use App\Rules\Uppercase;

$rules = [
    'required',
    new Uppercase,
    function($attribute, $value, $fail) {
        if ($value === 'foo') {
            return $fail($attribute.' is invalid.');
        }
    },
];

The package currently errors in the injectUniqueIdentifier() method. When exploding the rule, it is assumed the rule is always a string:

$parameters = explode(':', $rule);

I just ran into this issue and thought I'd let you know. I'm not sending in a PR; seems a rather easy fix to me so go ahead.

dwightwatson commented 6 years ago

Thanks for reporting this. Unfortunately I don't have the time to dedicate to fixing this implementation at the moment but I'm happy to accept any PR that can sort it out.