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

justincone's avatar

Fetching markdown from db displays curly braces (instead of processing them)

(Thanks in advance for your help with this. I'm sure I'm missing something very obvious.)

The problem

In a text field (email.body) in my database, I'm storing a simple bit of content:

Hi, {{ $user->first_name }}!

In my markdown email template, I'm calling this content like so:

{!! $email->body !!}

Unfortunately, the user's first name is not being resolved. Instead, I see the exact same text stored in the database, complete with curly braces:

Hi, {{ $user->first_name }}!

In other words, the curly braces aren't being processed at all. They're just being displayed like normal text.

What I've tried

I've tried escaping the curly braces in the db, like so:

Hi, @{{ $user->first_name }}!

But it has no effect. I simply see the exact same content in my mailer:

Hi, @{{ $user->first_name }}!

If I don't fetch the content from the database, and instead directly put Hi, {{ $user->first_name }}! in my mailer, then it does work. I see:

Hi, Justin!

Which is exactly what I would expect.

Any help would be greatly appreciated. Thank you!

0 likes
8 replies
justincone's avatar

Here's a screenshot that might explain the situation better:

image

jlrdw's avatar

Is $user coming from controller.

justincone's avatar

Yes, $user is coming from the controller:

$user = User::find(3962);

$email = ProductEmail::find(1);

return new MarkdownTest($user, $email);

And here's MarkdownTest:

class MarkdownTest extends Mailable
{
    use Queueable, SerializesModels;

    public $user;

    public $email;

    public function __construct(User $user, ProductEmail $email)
    {
      $this->user = $user;

      $this->email = $email;
    }

    public function build()
    {
        return $this->markdown('emails.product.test');
    }
}
jlrdw's avatar

You are testing, but does the mail work for real? You never said test in original post.

justincone's avatar

If I send the mail through my SMTP server, I get exactly the same results as when previewing the mailable in my browser.

Everything in the mail is fine, except the curly braces aren't being processed.

jlrdw's avatar

Send data as object or array at Loop through fields like you would do a normal View just displaying data.

justincone's avatar

Thanks for your help with this, @jlrdw. Unfortunately, I don't understand what you mean.

As I've continued testing this issue, I've discovered that it's easy to duplicate in any view (not just mailers).

I created a view with nothing in it except the following:

Hello, {{ $user->name }}
{!! $email->body !!}

That generates the following output:

Hello, Justin (which is correct)
{{ $user->name }} (which is not correct—it's just echoing the contents of the db)

The contents of $email->body in the db:

image

It's important that I can store variables in the database. I want to build a CMS (of sorts) that lets people create email campaigns. Those campaigns should allow variables.

But it appears that Laravel can't "double process" variables. In other words, it can retrieve the contents of my database field, but it can't then process the variables in that field.

There has to be some way around this, but I'm at a loss.

justincone's avatar
justincone
OP
Best Answer
Level 3

I now realize that what I'm trying to do is essentially impossible. I'm trying to parse data after it's already been parsed. :D

Thanks again for your help, @jlrdw .

Please or to participate in this conversation.