Reputation: 105
I am developing a website which contain a post submission. When I save the data from texterea, I noticed that the data is in html format rather than plain text. So, what is the best way to show the data in an article format? I am using tinymce editor.
I'm using laravel, thus I just simply use
auth()->user()->posts()->create([
'article' => $data['article'],
]);
To call, I use {{$data->article}}
. Please noted that, I only specifically show how I save only textera input.
This is my output Output
This is database Database image
This is expected ouput, without html tag. Expected output
Upvotes: 0
Views: 1749
Reputation: 94
Try this:
{ !! $data->article !! }
Blade statements {{ }} are sent to htmlspecialcharacters() to prevent XSS attacks. If you do not want your html to be escaped you have to use this syntax -> {!! !!}
https://laravel.com/docs/8.x/blade#displaying-unescaped-data
Upvotes: 2
Reputation: 105
Update: Simply use <?php echo $post_data->article;?>
will do the job. Can anyone explain the reason?
Output
Upvotes: 1
Reputation: 429
You can display html content by many ways in laravel. Here are some examples
Method 1:
@php
echo $data->article;
@endphp
Method 2:
{{ !! $data->article !! }}
Method 3:
{{ !! htmlspecialchars_decode($data->article) !! }}
OR
{{ !! html_entity_decode($data->article) !! }}
Upvotes: 0