0

How to format form validation error message in laravel 5 like below ??

The Date is not a valid date.

3

3 Answers 3

1

You can set custom validation messages in the resources/lang/en/validation.php file:

'custom' => [
    'date' => [
        'date' => 'The <strong>:attribute</strong> is not a valid date.',
    ],
],

If you want the attribute to be bold on all date validation messages (regardless of the field name), then you can set the message for the date key:

'date' => 'The <strong>:attribute</strong> is not a valid date.',
Sign up to request clarification or add additional context in comments.

Comments

0

use str_replace and then ask blade to parse the output as an html text, like this:

{!! str_replace( 'Date' , '<b>Date</b>' , 'The Date is not a valid date')  !!}

Comments

0

If you're using the basic validation error display and want to show the name of the field in bold, you can:

Using the 'en' language as an example.

  • Add the name of the field in a language file (resources/lang/en/validation.php) inside the attributes key:

    <?php
    return [
        'attributes' => [
            'my_field' => '<b>My Field</b>'
        ]
    ];
    
  • In the validation message display, just change the {{ $error }} to {!! $error !!}

Comments

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.