Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel validation array unique values

<?php
$validator = Validator::make($request->all(), [
  'myArray' => ['required', 'array', 'min:1', 'max:100', 'distinct'],
  'myArray.*' => ['required', 'integer', 'min:1', 'max:999999']
]);

if ($validator->fails()) {
  return [
    'status' => 400,
    'response' => $validator->errors()
  ];
}

$validated = $validator->validated();

// distinct is there for the uniqunes
 
PREVIOUS NEXT
Tagged: #laravel #validation #array #unique #values
ADD COMMENT
Topic
Name
9+1 =