0

I want to show my own message instead of one provided by the framework, So I did the following but it is not making any difference and showing default messages.

$message = [];
    foreach($request->get('estimates') as $key => $val)
    {
        $rules['estimates.'.$key] = 'required|integer';
        $message['estimates.'.$key] = 'Incorrect value';
    }
    $rules['technical_information'] = 'required';
    $rules['project_risks'] = 'required';

    $this->validate($request, $rules,$message);

1 Answer 1

3

I believe you need to adhere to the correct format for messages. Per the Laravel docs:

$messages = [
    'required' => 'The :attribute field is required.',
];
$validator = Validator::make($input, $rules, $messages);

The key in $messages needs to be the rule , and the value is the Message -- with a placeholder for the attribute name.

You can also specify messages per rule, per attribute by using dot syntax:

'username.required' => 'the field is required...'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.