Php 将刀片数据值转换为布局中的另一个值

Php 将刀片数据值转换为布局中的另一个值,php,laravel,laravel-5,laravel-blade,Php,Laravel,Laravel 5,Laravel Blade,我想将一个变量值转换为另一个变量值(两者都与键位于同一个表中),并在刀片布局中显示容器变量值。这两个变量都是通过控制器的with方法传递的。可能吗? 下面是我想要的东西的快速演示: # controller method public function build() { return $this ->view('emails.registration_following') ->with( ['name' => 'Nick', 'text' =>

我想将一个变量值转换为另一个变量值(两者都与键位于同一个表中),并在刀片布局中显示容器变量值。这两个变量都是通过控制器的
with
方法传递的。可能吗? 下面是我想要的东西的快速演示:

# controller method 
public function build()
{
    return $this
    ->view('emails.registration_following')
    ->with( ['name' => 'Nick', 'text' => 'Hello {{ $name }}'] ) # Here goes the thing
    ;
}
blade.php
看起来像:

<html>
    <body>
      <p> {{ $text }} </p>    
    </body>
</html>

{{$text}}


我的预期输出是
Hello Nick
,但我得到了
Hello{{{Nick}}
。我知道这里的括号被视为
String
,但如何绕开它呢

你试过下面这样吗

public function build()
{
    $name = 'Nick';
    return $this
    ->view('emails.registration_following')
    ->with( ['name' => $name , 'text' => 'Hello '.$name] ) # Here goes the thing
    ;
}

首先在函数中定义变量如何:

# controller method 
public function build()
{
    $name = 'Nick';

    return $this
      ->view('emails.registration_following')
      ->with( ['name' => $name, 'text' => "Hello $name"] ) # Here goes the thing
    ;
}

通过这种方式,您可以在视图中访问
$name
$text

和(['name'=>'Nick','text'=>“Hello$name”])
请使用双引号事实上,我不需要传递两个变量,只需传递一个,然后将所有需要的其他变量的值都输入即可形成预期的文本。
按照我的要求去做是个坏主意。谢谢。

这是个好主意。看着你的代码,我发现我不需要传递两个变量,只需要传递一个,然后输入它的值,所有这些都需要其他变量。谢谢。我怎么没看见?谢谢,@cf混蛋。这就是StackOverflow的用途。如果可能的话,请投票并接受:)这是个好主意。看着你的代码,我发现我不需要传递两个变量,只需要传递一个,然后将所有需要的其他变量都输入它的值。谢谢我怎么没看见呢?