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

Using ConditionalRules in NestedRules throws an exception. #47340

Closed
Lelectrolux opened this issue Jun 4, 2023 · 1 comment · Fixed by #47344
Closed

Using ConditionalRules in NestedRules throws an exception. #47340

Lelectrolux opened this issue Jun 4, 2023 · 1 comment · Fixed by #47344
Labels

Comments

@Lelectrolux
Copy link
Contributor

Laravel Version

v10.10.0

PHP Version

8.1.5

Database Driver & Version

No response

Description

When using Rule::when(...) inside a Rule::forEach(...) callback, an Object of class Illuminate\Validation\ConditionalRules could not be converted to string exception is thrown.

I suspect Illuminate\ValidationValidationRuleParser::prepareRule(...) does not deal with ConditionalRule.
I suspect it was an oversight of #40498.

If this is expected behavior, a mention in the docs might be warranted.

If I didn't understand something, please educate me.

I might try to make a failing test PR tomorrow, but I'm probably out of my depth to fix the actual bug itself.

Cheers, and thanks for the hard work.

Steps To Reproduce

Here is a minimum reproduction code in routes/web.php.

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;
use \Illuminate\Validation\Rule;

Route::get('/bug', function () {
    Validator::make(
        [
            'foo' => [
                [
                    'bar' => true
                ],
                [
                    'bar' => false
                ]
            ]
        ],
        [
            'foo.*' => Rule::forEach(fn(mixed $value, string $attribute) => [
                'bar' => Rule::when(true, ['accepted'], ['declined'])
            ])
        ]
    );
});
@Lelectrolux
Copy link
Contributor Author

That was quick, thanks @cosmastech & team ❤️

Just have to wait for realease day now 👍🏼

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

Successfully merging a pull request may close this issue.

2 participants