laravel-validator
laravel-validator copied to clipboard
Invoking "errors" method causes fatal error
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
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);
}
}