andersao / andersao/l5-repository

json_decode() expects parameter 1 to be string, array given when use validator & JSON data type

Aperta
#550 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
4.2k
Fork
880
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I use JSON data type in database column, when I store data I got error message〝json_decode() expects parameter 1 to be string, array given〞. If I comment validator(), the error is gone. Validator is default and all rules is empty. Anyone has idea for that if I want write some rules in validator? or maybe I should write rules in Request.

RepositoryEloquent:
>
public function validator()
{
return ScheduleValidator::class;
}

Model:
>

protected $casts = [
'id' => 'int',
'weekday' => 'array',
];

public function setMondayAttribute(string $value)
{
$this{'weekday->monday->start_time'} = json_decode($value)->start_time;
$this{'weekday->monday->end_time'} = json_decode($value)->end_time;
}

Validator:
>
protected $rules = [
ValidatorInterface::RULE_CREATE => [],
ValidatorInterface::RULE_UPDATE => [],
];

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.