Validating array with numerical keys #39257
-
Description:
ids = Steps To Reproduce:Please note that $ids is a json string |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
You are doing it wrong, you should pass the request or the whole request data into the make() method. Your rule checks for the
|
Beta Was this translation helpful? Give feedback.
-
Then use |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Validator make still points the wrong data. And required|integer does not make much sense you could do something like
|
Beta Was this translation helpful? Give feedback.
-
$validator = Validator::make($request->only('ids'), [
'ids' => 'required|array',
'ids.*' => 'integer'
]); Here are the differences between // Let's assume we have the following request data:
// name => 'John Doe'
// admin => true
// ids => [1, 2, 3, 4, 5]
request()->all()
// [
// 'name' => 'John Doe',
// 'admin' => true,
// 'ids' => [1, 2, 3, 4, 5]
// ]
request()->only('ids')
// [
// 'ids' => [1, 2, 3, 4, 5]
// ]
request()->get('ids')
// [1, 2, 3, 4, 5] When you use |
Beta Was this translation helpful? Give feedback.
-
With When test the following:
|
Beta Was this translation helpful? Give feedback.
Here are the differences between
all
,only
, andget
:When you use
get
you receive the value at the specified key. But what you really want is to get the key-value pair for the specified key.