I guess I can make a new separate blade and go from {!! preg_replace('/$(user)/', $user, $text) !!} to @include('text.blade', ['user' => Auth::user()->name]). Maybe this sollution'd be better than my current...
Mar 19, 2018
8
Level 1
Passing variable value in blade template
I have some html stored in db:
Hello, $user! ...
I retreive this html, put it to $text and pass to blade template.
In my template I have this:
@include('other.blade', ['text' => $text])
But exactly in my $text I want to replace $user by Auth::user()->name.
So I have this working example now:
@include('other.blade', ['text' => $text, 'user' => Auth::user()->name])
and in other.blade:
{!! preg_replace('/$(user)/', $user, $text) !!}
But I don't like my sollution. Even if I want to pass more variables to $text, my current code won't work. Any better sollutions and advices appreciated! Thanks!
Level 67
The simplest solution would be to not store your "template" in the database. Make a regular blade view for it. Nothing else would need to be done.
Hello, {{ Auth::user()->name }}, how are you?
1 like
Please or to participate in this conversation.