andersao / andersao/l5-repository

Validator gives false negative with attribute accessor

未關閉
#403 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
4.2k
分支
880
PR 合併指標
30 天內沒有已合併 PR

描述

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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。