Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Validating array using asterisk (*) against another array field doesn't do anything #11648

Closed
bridgeport opened this issue Jan 1, 2016 · 6 comments

Comments

@bridgeport
Copy link

Hi,

Using Laravel 5.2.6, I'm extending the Request class and returning a rule, such as:

$rules = [
    'locations.*.phones.*.number' => 'required_with:locations.*.phones.*.phone_type_id',
];

When trying to validate a multi-dimensional array field against another multi-dimensional array field using the asterisk (*) approach, it doesn't have any impact. So, it's not clear how to get the following to function if the target field also includes an asterisk:

required_if
required_unless
required_with
required_with_all
required_without
required_without_all

Is this approach not yet supported?

Thanks.

@GrahamCampbell GrahamCampbell changed the title Validating array using asterisk (*) against another array field doesn't do anything [5.2] Validating array using asterisk (*) against another array field doesn't do anything Jan 6, 2016
@GrahamCampbell
Copy link
Member

Thanks for getting in touch.

Is this approach not yet supported?

I'd have to assume so. Ping @taylorotwell for details.

@danpastori
Copy link

I have the same issue if a little extra code helps.

If I do an asterisk for a validation rule it doesn't work, but if I add a hard coded index, it works correctly.

Doesn't work:

$cafeValidator = Validator::make( $request->all(), [
    'cafes'             => 'array',
    'cafes.*.name'      => 'required_with:cafes'
]);

Works:

$cafeValidator = Validator::make( $request->all(), [
    'cafes'             => 'array',
    'cafes.0.name'      => 'required_with:cafes'
]);

If any more code is needed from me let me know!

@themsaid
Copy link
Member

This is a proposed fix #11927

@taijuten
Copy link

taijuten commented Apr 5, 2016

Although that fix has been merged, I'm still finding this issue, and this issue remains open. Can anyone else confirm that this isn't fixed in all cases?

I'm trying to use the before and after validation on dates, as part of an array input.

    $validator = Validator::make(
        $request->all(),
        [
            'sessions'          => 'required | array',
            'sessions.*.id'         => 'sometimes | integer | exists:sessions,id,event_id,'.$event->id,
            'sessions.*.title'      => 'required',
            'sessions.*.starts'         => 'required | date | before:sessions.*.ends',
            'sessions.*.ends'       => 'required | date | after:sessions.*.starts'
        ]
    );

@rela589n
Copy link

rela589n commented Feb 6, 2020

I have another issue.

'q.new.*.v.*.text' => [
        'required',
        'min:2',
        'max:128',
]

That works and i can see errors in my form, when one of elements fails validation, but when i add new q.new.*.v item and send form, added element is not flashed to the storage, and i can't access it using old() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants