Skip to content
Discussion options

You must be logged in to vote
$validator = Validator::make($request->only('ids'), [
    'ids' => 'required|array',
    'ids.*' => 'integer'
]);

Here are the differences between all, only, and get:

// 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 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.

Replies: 6 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@ukenpachi
Comment options

Comment options

You must be logged in to vote
1 reply
@ukenpachi
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@ukenpachi
Comment options

@dennisprudlo
Comment options

@ukenpachi
Comment options

@dennisprudlo
Comment options

Answer selected by ukenpachi
Comment options

You must be logged in to vote
2 replies
@ukenpachi
Comment options

@jmarcher
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #39256 on October 19, 2021 10:54.