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

[Bug]: required_without and required_without_all validation not working properly. #4128

Open
1 task done
YouneselBarnoussi opened this issue May 12, 2024 · 0 comments
Open
1 task done
Labels

Comments

@YouneselBarnoussi
Copy link

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.55

What version of Laravel are you using?

10.48.10

What version of PHP are you using?

8.2.16

Describe your issue

I am doing a user import as follows

class UsersImport implements ToModel, WithValidation
{
    public function rules(): array
    {
        return [
            'email' => [
                'nullable',
                'email',
                'required_without_all:first_name,last_name',
            ],
            'first_name' => [
                'nullable',
                'required_without:email',
            ],
            'last_name' => [
                'nullable',
                'required_without:email',
            ],
        ];
    }
}

The RowValidator class formatRules function doesn't properly format these rules as this is the output from that function

'email' => [
    'nullable',
    'email',
    'required_without_all:*.first_name,last_name',
],
'first_name' => [
    'nullable',
    'required_without:email',
],
'last_name' => [
    'nullable',
    'required_without:email',
],

How can the issue be reproduced?

See example above

What should be the expected behaviour?

The expected output for the rules should be:

'email' => [
    'nullable',
    'email',
    'required_without_all:*.first_name,*.last_name',
],
'first_name' => [
    'nullable',
    'required_without:*.email',
],
'last_name' => [
    'nullable',
    'required_without:*.email',
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant