Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store and render Laravel blade templates from the database

How can I render Blade templates from the database (instead of using a blade template file)?

I've checked this Render template from blade template in database but for some reason is not replacing the variables in the template. It's giving a Notice: Undefined Variable.

Any ideas?

Thanks in advance

like image 912
TJ is too short Avatar asked Jan 20 '26 03:01

TJ is too short


1 Answers

For these, who stumble across this just now: In Laravel 9, it's implemented natively.

https://laravel.com/docs/9.x/blade#rendering-inline-blade-templates

use Illuminate\Support\Facades\Blade;
 
return Blade::render('Hello, {{ $name }}', ['name' => 'Julian Bashir']);
like image 159
shaedrich Avatar answered Jan 23 '26 20:01

shaedrich