andersao / andersao/l5-repository

Validator gives false negative with attribute accessor

Open
#403 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4.2k
Forks
880
PR merge metrics
No merged PRs in 30d

Description

Working with Laravel 5.4. I have an [attribute accesor](https://laravel.com/docs/5.4/eloquent-mutators#defining-an-accessor) defined on my model as follows:

`public function getFooAttribute($value)
{
return $value ? "YES" : "NO";
}`

The `foo` field is Boolean, so the validator rules for that field are:

`'foo' => 'required|boolean'` for create

and

`'foo' => 'boolean'` for update

However, when I try to create or update I get the message "foo" : [ "The foo field must be true or false." ]

I'm guessing the value passed to or used by the validator is the value returned from the attribute accessor, because if I comment it I get no errors.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.