andersao / andersao/l5-repository

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

Aberta
#550 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
PHP
Estrelas
4.2k
Forks
880
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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 => [],
];

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.