1

I'm working on a custom request validator with custom error messages for Laravel 5. Is there a way I could display HTML in returned messages?

My goal is to be able to include links in the message, ie:

"You need a lottery ticket number. Don't have one? <a href='#'>Register Here.</a>"

I've searched different forums and couldn't find a solution. Below isn't applicable in my case: https://laracasts.com/discuss/channels/general-discussion/html-in-httprequests-custom-error-messages

EDIT:

SOLVED.

I'm using custom messages set in a custom Request:

 public function messages()
{
    return [
        'dob.eighteen'    => 'You must be 18 or older to take part in this competition.',
        'photo.required'    => 'You must upload a photo of the space.',
        'photo.mimes' => 'The uploaded file must be a photo in .jpeg or .png format.',
        'name.required'      => 'Please enter your full name.',
        'ticket.required'      => 'You need a ticket number to enter. Don\'t have one? <a href="#">Register Here.</a>',
        'email.required'      => 'The e-mail field is required.',
        'dob.required'      => 'The date of birth is required.',
        'postcode.required'      => 'The date of birth is required.',
        'postcode.postcode'      => 'The postcode you entered is incorrect.',        ];
}

The reason why the above link wasn't applicable is because I want to keep my code neat and store all the error messages in one file together with request validation rules.

The solution was so simple that I completely missed it before.

Thanks for helping.

3
  • You need to specify why it's not applicable, also some code would be nice as well, because so far there's not really enough information to go on. Commented Sep 1, 2015 at 15:42
  • Do you want to change a message from a form validation error or you just want to return a generic error message in html? Commented Sep 1, 2015 at 16:53
  • 1
    FYI: It's completely okay to self-answer if you found the answer yourself. Commented Sep 4, 2015 at 21:04

1 Answer 1

1

The errors are displayed using {{ $error }} tag in a blade template.

To display a message that contains html = If you don't want the data to be escaped, you should use the following syntax: {!! $error !!}

Thanks for helping.

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

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.