spik3s
spik3s

Reputation: 1199

Laravel: Display html in app/http/requests custom error messages

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.

Upvotes: 1

Views: 1962

Answers (1)

spik3s
spik3s

Reputation: 1199

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.

Upvotes: 1

Related Questions