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

How to make Custom Rule with Eloquent work? #364

Closed
dododaphne opened this issue Jan 5, 2019 · 1 comment · Fixed by #419
Closed

How to make Custom Rule with Eloquent work? #364

dododaphne opened this issue Jan 5, 2019 · 1 comment · Fixed by #419

Comments

@dododaphne
Copy link

This is my request class:

class registerRequest extends FormRequest
{
    public function rules()
    {
        return [
            'email' =>[
                    'bail',
                    'required',
                     new EmailMustNotInUserDB
                ]
        ];
    }
}

This is my custom rule class:

class EmailMustNotInUserDB implements Rule
{
    public function passes($attribute, $value)
    {
        return User::where('email',$value)->count()==0;
    }

    public function message()
    {
        return trans('validation_custom.email_must_not_in_user_db');
    }
}

And I get an error:

local.ERROR: trim() expects parameter 1 to be string, object given {"exception":"[object] (ErrorException(code: 0): trim() expects parameter 1 to be string, object given at /var/www/core/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php:217)

If I comment out new EmailMustNotInUserDB in request class, the jsvalidation works, so how to make it work?(I'm using laravel 5.7)

bytestream added a commit to bytestream/laravel-jsvalidation that referenced this issue Mar 28, 2019
bytestream added a commit to bytestream/laravel-jsvalidation that referenced this issue Mar 28, 2019
@bytestream
Copy link
Collaborator

Due to the volume of issues I'm afraid I'm closing this issue due to lack of activity. This avoids fellow collaborators wasting time investigating this issue, and also prevents giving a false impression that it will eventually be addressed.

To the reporter, please reopen if you still encounter this on the latest version providing a minimal test case. You can also contribute directly by submitting a PR.

Thanks.

@bytestream bytestream linked a pull request Mar 13, 2020 that will close this issue
bytestream added a commit to bytestream/laravel-jsvalidation that referenced this issue Mar 15, 2020
@bytestream bytestream linked a pull request Mar 15, 2020 that will close this issue
bytestream added a commit that referenced this issue Mar 15, 2020
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

Successfully merging a pull request may close this issue.

2 participants