Steve Silva
Steve Silva

Reputation: 21

return or display valid options in Rule::in when fail validate in laravel

in my controller i have this validator

...
$request->validate([
        'id' => ['bail', 'required', 'string'],
        'live' => [Rule::in(['yes', 'no'])],
    ]);
...

and my response if the rule Rule::in fails is this

{
"message": "The given data was invalid.",
"errors": {
    "live": [
        "The selected live is invalid."
    ]
}
}

now my question is how can I return the possible values of Rule:in within that response? in this case: "yes" and "no"

Upvotes: 2

Views: 484

Answers (0)

Related Questions