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

yansusanto's avatar

How to display 'value' from database in an article?

I'm not sure if I phrase the question correctly but I'd like to know if there is a way to insert database value, say {{ $statistic->female->count() }} within an article. Yes, I have a blog using Laravel framework.

That way, I don't have to go back to edit the article if there is a change in value.

0 likes
7 replies
Snapey's avatar

You can only use Blade tags once, so if you already use it to get the blog article then you cannot loop around and use blade again on the content you just imported

So the answer depends on your CMS

1 like
yansusanto's avatar

That makes sense, @Snapey

If you do have a minute, mind if have a look at this article which is run on WordPress.

Getting the statistics is the easy part, updating them across the site is really time-consuming. And it is for this reason that I learn Laravel, hoping that I could update the data backend and update them across the site.

How would you approach this? As always, I value your suggestion.

Vilfago's avatar

I handled it this way :

  • store in db the article with in text something like "[statistic->female->count]"
  • when getting the article, use regex to replace the code with the current value.

Cons : I have a list of value to be replaced, and I can only use them. Pros : maybe a way to automatise the replacement ?

1 like
yansusanto's avatar

If possible, I'd like to hear other opinion on this or if anyone has ever done this before, please point me in the right direction.

Thanks!

yansusanto's avatar

@Vilfago

Or maybe only using double quote, as the variables in them are interpreted by php ?..... use unescaped blade({!! !!})

I did try but to no avail.

Please or to participate in this conversation.