andersao / andersao/l5-repository

Issues with date mutator at model and the repository validator.

Aperta
#274 8 commenti 1 reazione 0 assegnatari Vedi su GitHub
bug
Lingua principale
PHP
Stelle
4.2k
Fork
880
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.