0

Hello I am trying to return a page message if a query fails to execute in laravel. It seems like the characters are escaped and the ouput is instead of being bold the output is actually appears like this.

<strong>Failed!</strong> No Good

my code is

try {
       $product->save();
    } catch ( \Illuminate\Database\QueryException $e) {
       // var_dump($e->errorInfo);
        //$messageTest = "failed";
        $messageTest = "<strong>Failed!</strong> No good";
        $isSuccess = 0;
    }

     return view('admin.createProduct',compact('isSuccess','categories','messageTest'));

i call it with {{$messateTest}} in my view.

Any suggestions on the subject ?

rematnarab
  • 1,277
  • 4
  • 22
  • 42

3 Answers3

1

This should work (the variable should be $messageTest):

@{{ $messageTest }}

It will not escape the html

1

You should write inside the blade like below for view HTML Attr.

{!! $messateTest !!}
1

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

You should try this:

{!! $messageTest !!}

If you do not want your data to be escaped, you may use the following syntax:

{!! $variable !!}

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45