andersao / andersao/l5-repository

Issues with date mutator at model and the repository validator.

未关闭
#274 8 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
PHP
星标
4.2k
派生
880
PR 合并指标
30 天内没有已合并 PR

描述

I have an attribute named as "dtinicio" who is casted to date by my model:

``` php
// Model.php
protected $dates = ['dtinicio'];
```

My application uses the format "d/m/Y" by default, so i've implemented the mutator at the model:

``` php
// Model.php
protected $dates = ['dtinicio'];

public function setDtinicioAttribute($value)
{
$this->attributes['dtinicio'] = empty($value) ? null : Carbon::createFromFormat('d/m/Y', $value)->setTime(0, 0);
}
```

MyRepository extends BaseRepository from this package, and i've implemented the $rules as documented.

``` php
// MyRepository.php
class MyRepository extends BaseRepository
{
protected $rules = [
'dtinicio' => 'date_format:d/m/Y'
];
}
```

I'm facing issues trying to create or update those values because BaseRepository is changing the format, in the methods "create()" and "update()", just before the call on validator.

The error appears even if i remove the rule for dtinicio, the only way to pass through it is disabling the validator completely from this repository.

I think it's related to #120.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。