Reputation: 310
I want to use a variable value into another one (both are in the same table as keys) and display in a blade layout the container variable value. Both variables are passed using the with
method from the controller. Is that possible?
Here a quick demo of what I'm loooking for :
# controller method
public function build()
{
return $this
->view('emails.registration_following')
->with( ['name' => 'Nick', 'text' => 'Hello {{ $name }}'] ) # Here goes the thing
;
}
And the blade.php
looks like :
<html>
<body>
<p> {{ $text }} </p>
</body>
</html>
The expect output by me is Hello Nick
but I got Hello {{Nick}}
. I know that brackets here, are treated like String
but how to circumvine that?
Upvotes: 1
Views: 288
Reputation: 310
In fact, I did not need to pass two variables but just one and put in its value all needed other variables to form my expected text. It was a bad idea to do what I was asking for. Thank you.
Upvotes: 1
Reputation: 941
with( ['name' => 'Nick', 'text' => "Hello $name"] )
Please use double quote
Upvotes: 0
Reputation: 1833
How about defining the variable in the function first:
# controller method
public function build()
{
$name = 'Nick';
return $this
->view('emails.registration_following')
->with( ['name' => $name, 'text' => "Hello $name"] ) # Here goes the thing
;
}
In this way, you have both $name
and $text
accessible in the view.
Upvotes: 1
Reputation: 1003
Have u tried like this below?
public function build()
{
$name = 'Nick';
return $this
->view('emails.registration_following')
->with( ['name' => $name , 'text' => 'Hello '.$name] ) # Here goes the thing
;
}
Upvotes: 0