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

Invoking "errors" method causes fatal error #19

Open
supercoffee opened this issue Jul 3, 2016 · 1 comment
Open

Invoking "errors" method causes fatal error #19

supercoffee opened this issue Jul 3, 2016 · 1 comment

Comments

@supercoffee
Copy link

supercoffee commented Jul 3, 2016

After calling the "passes" method to validate data, calling the errors() method triggers a fatal error by attempting to invoke the all() method on an array.

My example code

        $data = $this->request->json();
        $this->validator->with->data($data)->passes(ValidatorInterface::RULE_CREATE);
        $this->validator->errors();

The error

PHP Fatal error:  Call to a member function all() on array in /var/www/my.app/vendor/prettus/laravel-validation/src/Prettus/Validator/AbstractValidator.php on line 92
@brunoneve
Copy link

brunoneve commented Jul 9, 2016

Hi @supercoffee,

use this

use Prettus\Validator\Contracts\ValidatorInterface;

   public function update(array $data, $id)
    {
        try {

            $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE);
            return $this->repository->update($data,$id);

        } catch (ValidatorException $e){
            return Response::json([
                'error' => true,
                'message' => $e->getMessageBag()
            ],400);
        }
}

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