1

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"

  • You need to use a [Form Request](https://laravel.com/docs/9.x/validation#customizing-the-error-messages) or the Facade [Validator::make](https://laravel.com/docs/9.x/validation#manual-customizing-the-error-messages) to customize the message. – MrEduar Feb 18 '22 at 02:59
  • `live` parameter value anything without `yes` or `no` will make this validation expecetion. So, make sure you are passing `yes` or `no` as `live` parameter value. – Tamim Feb 18 '22 at 06:10
  • I don't understand a bit your comment – Steve Silva Feb 18 '22 at 15:38
  • Since this is a `boolean` why dont you use a **radio input** ? – medilies Feb 23 '22 at 19:17

0 Answers0