andersao / andersao/l5-repository

Issues with date mutator at model and the repository validator.

Offen
#274 8 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
PHP
Sterne
4.2k
Forks
880
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.