Php 在邮件刀片视图中的另一个变量中使用变量

Php 在邮件刀片视图中的另一个变量中使用变量,php,html,laravel,Php,Html,Laravel,我正在使用Laravel中的邮件库发送html电子邮件,其中包含传递到刀片视图的自定义数据 当邮件必须呈现从数据库中的一行(其中包含我通过视图传递的变量)获取的html时,就会出现问题 这是我在mailable类中的构建函数 公共函数构建() { 返回$this->from('hello@test.it') ->视图(“视图”) ->与([ 'url'=>'https://google.com', 'text'=>this->parameters->text, ]); } 然后在刀片视图中:

我正在使用Laravel中的邮件库发送html电子邮件,其中包含传递到刀片视图的自定义数据

当邮件必须呈现从数据库中的一行(其中包含我通过视图传递的变量)获取的html时,就会出现问题

这是我在mailable类中的构建函数

公共函数构建()
{
返回$this->from('hello@test.it')
->视图(“视图”)
->与([
'url'=>'https://google.com',
'text'=>this->parameters->text,
]);
}
然后在刀片视图中:


{!!$text!!}
这就是$text变量的外观:


这是我的邮件文本


链接href应该包含url变量值,而不是不传递变量名本身

我没有亲自尝试,但您可以尝试使用
Blade::compileString()
,即:

public function build()
{
    return $this->from('hello@test.it')
      ->view('view')
      ->with([
        'url'     => 'https://google.com',
        'text' => \Blade::compileString($this->parameters->text),
    ]);
}

一个简单的解决方案是使用php格式化:

public function build()
{
    return $this->from('hello@test.it')
     ->view('view')
     ->with([
       'text' => str_replace('{{ $url }}','https://google.com',$this->parameters->text)
      ]);
 }

这无法工作,因为str_replace中传递的$url变量将被解释为变量而不是字符串。这看起来很好,但它会删除变量而不替换任何内容。请尝试使用普通的var扩展
它只需在“$url”中转换url这就是代码现在的样子:
lang php return$This->from('hello@test.it')->view('view')->带有(['url'=>'https://google.com“,”text'=>this->parameters->text,];
在数据库中:
langhtml这是我的邮件文本