0

Here my code :

$rules = [
        'name' => 'required|string|max:255',
        'price' => 'required|numeric|min:0',
        'unit' => 'required|in:piece,kg,m',
        'price_type' =>'required|string',
        'service' => [
            'string',
            'required',
            Rule::in($services_ids->all()),
        ],
        'facility' => [
            'string',
            'required',
            Rule::in($facilities_ids->all()),
        ],
        'conciergeries' => [
            'array',
            'required',
            Rule::in($conciergeries_ids->all()),
        ],
    ];

    $custom_messages = [
        'required' => 'Vous devez sélectionner un(e) :attribute.'
    ];

    $validated = request()->validate($rules, $custom_messages);

The problem is that my custom_messages only works with 'name', 'price', 'unit', 'price_type' but not with 'service', 'facility' and 'conciergeries'.

Questions :

  • How to apply my custom messages with 'service', 'facility' and 'conciergeries' too ?
  • How to create a custom message for specifically one field ?

Thank's !

1

1 Answer 1

2

You just need to specify for which field you want to change the message

Try it like:-

$custom_messages = [
    'service.required' => 'Your custom message for required service',
    'service.string' => 'Your custom message of service should be string',];

And same process for facility and conciergeries.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank's it's okay now for 'service' and 'facility', but i don't see the error message with 'conciergeries', i think it's because it require an array field, do you have an idea to see the error message ?
Oh the message of conciergeries error is not display because of my blade view, sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.