andersao / andersao/l5-repository

Issues with date mutator at model and the repository validator.

Abierto
#274 8 comentarios 1 reacción 0 asignados Ver en GitHub
bug
Lenguaje dominante
PHP
Estrellas
4.2k
Forks
880
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.