如何将变量传递给降价? laravel 邮件

How to pass variable to markdown? laravel mail

我正在使用 MailMessage 向 mailtrap 发送邮件消息,我传递了一个变量 email

我的问题是无法识别我在降价中传递的变量。它 returns 下面是一个错误

Facade\Ignition\Exceptions\ViewException: Undefined variable: email (View: /var/www/resources/views/ema...

有人知道传递和获取变量 from-to markdown 的正确方法是什么吗?


这是我的代码

return (new MailMessage)
    ->greeting('hello')
    ->line('Innerline sample')
    ->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
    ->line('sample')
    ->markdown('emails.reset')
    ->with('email', 'orange@gmail.com');

这是我的 markdown 样子

@component('mail::layout', ['email' => $emaill])

//more codes here

{{ $email }}

//more codes here

@endcomponent

将变量作为第二个参数传递。

return (new MailMessage)
    ->greeting('hello')
    ->line('Innerline sample')
    ->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
    ->line('sample')
    ->markdown('emails.reset', [
        'email' => 'orange@gmail.com',
      ]);

https://laravel.com/docs/8.x/mail#markdown-mailables

我最终通过使用 compact 而不是数组得到了解决方案。我在下面更改了这一行,一切正常。

->markdown('emails.reset', compact('email'))

来自 laracasts 的 @sibongisenimsomis 积分

Apparently passing variables to Markdown from Notification class works, differently. I used compact on my solution, after struggle for about an hour cause I was referring to another example which was using with, on a Mailable class.

https://laracasts.com/discuss/channels/laravel/passe-some-variables-to-the-markdown-template-within-a-notification