Php 如何在Laravel中将标记文字传递给标记刀刃?

Php 如何在Laravel中将标记文字传递给标记刀刃?,php,laravel,email,laravel-mail,Php,Laravel,Email,Laravel Mail,我需要在Laravel中发送降价电子邮件,但此电子邮件的文本必须是可编辑的。当我将$body传递到相关视图时,它显示如下: $body='' #导言 你好{{$username} 您{{$family}的主体。 @组件('mail::button',['url'=>'') 按钮文本 @端部元件 ''' 在刀片服务器的相关视图中: @组件('mail::message') {{$body}} 谢谢, {{config('app.name')} @端部元件 这就是输出: 有人知道为什么会发生这种

我需要在Laravel中发送降价电子邮件,但此电子邮件的文本必须是可编辑的。当我将
$body
传递到相关视图时,它显示如下:

$body=''
#导言
你好{{$username}
您{{$family}的主体。
@组件('mail::button',['url'=>'')
按钮文本
@端部元件
'''
在刀片服务器的相关视图中:

@组件('mail::message')
{{$body}}
谢谢,
{{config('app.name')} @端部元件
这就是输出:


有人知道为什么会发生这种情况吗?

您没有将其作为字符串传递,而是将整个身体与上述所有变量一起放在现有的视图中,如下所示:

  @component('mail::message')
    
       hi {{ $username }} 
       The body of your {{ $family }}.

       @component('mail::button', ['url' => ''])
          Button Text
       @endcomponent
    
       Thanks,<br>
       {{ config('app.name') }}
    @endcomponent
public function __construct($username, $family)
    {
        $this->username = $username;
        $this->family = $family;
    }

    
    public function build()
    {
        $data['username'] = $this->username;
        $data['family'] = $this->family;

        return $this
            ->view('your_blade', $data)
            ->subject('Subject');
    }
然后,您的可邮寄类将如下所示:

  @component('mail::message')
    
       hi {{ $username }} 
       The body of your {{ $family }}.

       @component('mail::button', ['url' => ''])
          Button Text
       @endcomponent
    
       Thanks,<br>
       {{ config('app.name') }}
    @endcomponent
public function __construct($username, $family)
    {
        $this->username = $username;
        $this->family = $family;
    }

    
    public function build()
    {
        $data['username'] = $this->username;
        $data['family'] = $this->family;

        return $this
            ->view('your_blade', $data)
            ->subject('Subject');
    }

然后,您的变量将显示在给定的视图中。

您将整个身体与上述所有变量一起放在现有的视图中,而不是作为字符串传递,如下所示:

  @component('mail::message')
    
       hi {{ $username }} 
       The body of your {{ $family }}.

       @component('mail::button', ['url' => ''])
          Button Text
       @endcomponent
    
       Thanks,<br>
       {{ config('app.name') }}
    @endcomponent
public function __construct($username, $family)
    {
        $this->username = $username;
        $this->family = $family;
    }

    
    public function build()
    {
        $data['username'] = $this->username;
        $data['family'] = $this->family;

        return $this
            ->view('your_blade', $data)
            ->subject('Subject');
    }
然后,您的可邮寄类将如下所示:

  @component('mail::message')
    
       hi {{ $username }} 
       The body of your {{ $family }}.

       @component('mail::button', ['url' => ''])
          Button Text
       @endcomponent
    
       Thanks,<br>
       {{ config('app.name') }}
    @endcomponent
public function __construct($username, $family)
    {
        $this->username = $username;
        $this->family = $family;
    }

    
    public function build()
    {
        $data['username'] = $this->username;
        $data['family'] = $this->family;

        return $this
            ->view('your_blade', $data)
            ->subject('Subject');
    }

然后,您的变量将显示在给定视图中。

只需将其更改为查看刀片:

{!! $body !!}

只需将其更改为查看刀片:

{!! $body !!}

您的
$body
变量是一个字符串文本,我不知道您认为这是如何工作的?所以。。。我怎样才能转换它呢?你的
$body
变量是一个字符串文本,我不知道你认为这是如何工作的?所以。。。我怎样才能转换这个?