Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

serverus14's avatar

HTML and PHP tags saved in DB, how to show it on blade?

Hi good day guys,

Would like to ask on how to show the html and php saved from db to a blade template?

e.g. db entry:

@php $world = 'Universe'; @endphp
<p>Hello {{$world}}</p>

blade template - $content->description contains the db entry:

<div>{{$content->description}}. Lorem ipsum... </div>
0 likes
16 replies
serverus14's avatar

Thanks for the info :) Do you have any idea how to make it work? Currently, code above is not working. Been trying some tweaks and changes but still no luck :(

serverus14's avatar

from db, tbl_plan.description

@php $world = 'Universe'; @endphp
<p>Hello {{$world}}.</p>

from index.blade.php (not sure how to implement it here)

<div>
    {{$plan->description}}
    Lorem ipsum... 
</div>

expected output

<div>
    <p>Hello Universe</p>
    Lorem ipsum... 
</div>
V9द's avatar

You Can use Like this {!!$plan->description!!}

serverus14's avatar

Hi @V9द,

Tried that one

<div>
        {!!$plan->description!!}
        Lorem ipsum... 
</div>

But the browser output is (php is not rendered)

<div>
        @php $world = 'Universe'; @endphp
        Hello {{$world}}.
        Lorem ipsum... 
</div
V9द's avatar

Why you are storing php tags in database

serverus14's avatar

To manage the page, dynamically. Just like an email template with php tags :)

V9द's avatar

@serverus14 I think this in not best approch. I suggest you first have look on the laravel documents and tutorials and than try it.

serverus14's avatar

Yes, it maybe not the best approach for this but we have come into a scenario like this and we're stuck :D Let's say I want to have a CRUD for an email template. PHP tags are present in the template. How am I gonna edit it?

Snapey's avatar

You are talking about 'php tags' but what you are showing is blade tag @php

You render the content raw with blade {!! data!!} but then it contains blade tags. It would need to pass through the render process for a second time for any blade tags in data to be processed.

You may be able to render the data before passing it to the view but I doubt this is within your level of ability

serverus14's avatar

Oh, my bad. hahaha It was supposed to be a native php tag in the db. But still I've been looking for some fix or alternative where php and html are both rendered in a blade template.

Snapey's avatar

Then use the raw output {!! <p>You can be hacked</p> !!}

jlrdw's avatar
jlrdw
Best Answer
Level 75

USE a safe plugin for this sort of thing. If it doesn't work in blade, then don't use blade.

Or take a chance getting hacked. But don't have a site with people's personal information that can be hacked so easily.

1 like
serverus14's avatar
USE a safe plugin for this sort of thing. If it doesn't work in blade, then don't use blade.

Best answer for my simple not complicated question :P Thanks @jlrdw

Please or to participate in this conversation.