“A validação do Laravel existe uma matriz” Respostas de código

Como verificar existir na matriz na validação de regra Laravel

['someProperty' => ['required', Rule::in(['needed', 'stuff'])]];
Matio

IN_ARRAY Validação Laravel

I found a better solution. The validate in_array expects the array to be one of
the parameters in the request. The in: answer will not work if you have 
commas in the array. To use the in_array without having to create a new rule 
you can simply do: ( Make sure you include the .* at the end )

$this->allslots = array('10:00:00', '10:10:00', '10:20:00', '10:30:00', '10:40:00', '10:50:00', '11:00:00', '11:10:00', '11:20:00', '11:30:00', '11:40:00', '11:50:00', '12:00:00', '12:10:00', '12:20:00', '12:30:00', '12:40:00', '12:50:00', '13:00:00', '13:10:00', '13:20:00', '13:30:00', '13:40:00', '13:50:00', '14:00:00', '14:10:00', '14:20:00', '14:30:00', '14:40:00', '14:50:00', '15:00:00', '15:10:00', '15:20:00', '15:30:00', '15:40:00', '15:50:00', '16:00:00', '16:10:00', '16:20:00', '16:30:00', '16:40:00', '16:50:00');

$request['allslots'] = $this->allslots;

validate($request, [
  'field' => 'required|in_array:allslots.*',
]);
Lokesh003Coding

A validação do Laravel existe uma matriz

//Be careful it does multiple queries.
//'document_group_ids.*' => 'exists:document_groups,id'

public function rules(): array
{
   return [
       'document_type_id' => 'required|integer|exists:document_types,id',
       'document_group_ids' => 'required|array',
       'document_group_ids.*' => 'exists:document_groups,id',
    ];
}
Murat Çakmak

IN_ARRAY Validação Laravel

in:foo,bar,...

The field under validation must be included in the given list of values. Since 
this rule often requires you to implode an array, the Rule::in method may be 
used to fluently construct the rule:

'field' => 'required|in:' . implode(',', ['value1', 'value2']),
Lokesh003Coding

O valor de verificação de validação de Laravel deve ser um dos matrizes

'item' => [ Rule::in($my_arr) ],
Arrogant Alligator

A validação do Laravel existe uma matriz

$request = [
    'ids' => [1, 2, 3, 4],
];

$rules = [
    'ids' => 'required|array',
    'ids.*' => 'exists:users,id', // check each item in the array
];

$validator = Validator::make($request, $rules);

dd($validator->passes(), $validator->messages()->toArray());
Murat Çakmak

Respostas semelhantes a “A validação do Laravel existe uma matriz”

Perguntas semelhantes a “A validação do Laravel existe uma matriz”

Mais respostas relacionadas para “A validação do Laravel existe uma matriz” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código