1
Consider this array:
protected $filter = [
'preco' => 'required;double(1,4)',
'email' => 'required;email'
];
Step by the foreach:
protected function bootFilterPost() {
foreach ($this->filter as $key => $value):
$this->postRules[$key] = preg_split('/(;)/', $value);
endforeach;
var_dump($this->postRules);
}
and I have this exit:
array(2) {
["preco"]=>
array(2) {
[0]=>
string(8) "required"
[1]=>
string(11) "double(1,4)"
}
["email"]=>
array(2) {
[0]=>
string(8) "required"
[1]=>
string(5) "email"
}
}
but I would need it to go out that way:
array(2) {
["preco"]=>
array(2) {
["required"]=>
string(8) "true"
["double"]=>
string(11) "1,4"
}
["email"]=>
array(2) {
["required"]=>
string(8) "true"
["email"]=>
string(5) "true"
}
}
that is, I need the values to be inserted as keys and to these the string value ("true") or booleam(true);
The pattern is always this: if it’s just a word, stay
"palavra" => true
, but if there are any parentheses, stay"palavra" => "parenteses"
? Is there any other format that should be considered?– Woss
Your question is not very well defined in terms of output. I remember that Laravel has many validation rules that do not end in
true
, such asmin
,max
,different
,digits
, etc....– Isac
@Andersoncarloswoss exactly
"palavra" => true
as described by you. In the case of double value(1,4) would be["double"] => "1,4"
. This would be the different format to be considered.– Cleber Martins
@Isac, I would create a string and convert it to array, but I couldn’t find a formula for that!
– Cleber Martins