Skip to content

Custom Validation Rules don't work when used with multiple built-in rules #23750

@apasov

Description

@apasov
  • Laravel Version: 5.6.14
  • PHP Version: 7.2.3
  • Database Driver & Version: MariaDB 10.2.14

Description:

It only works when combined with single built-in rule. Trying to use chained rules throws an error.

Steps To Reproduce:

This works:

$request->validate([
    'name' => 'string|max:255',
]);

And this works as well:

use App\Rules\CustomValidationRule;

$request->validate([
    'name' => ['string', new CustomValidationRule],
]);

But this fails:

use App\Rules\CustomValidationRule;

$request->validate([
    'name' => ['string|max:255', new CustomValidationRule],
]);

and throws an error:

message: Method Illuminate\Validation\Validator::validateString|max does not exist.
exception: BadMethodCallException
file: vendor/laravel/framework/src/Illuminate/Validation/Validator.php
line: 1146

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions