【问题标题】:Laravel Mail view not returning passed dataLaravel 邮件视图不返回传递的数据
【发布时间】:2018-07-30 05:29:20
【问题描述】:

我正在尝试使用 Laravel 默认的 Mail 门面发送电子邮件:-

Mail::to($user->email)->send(New NotifyUserExpiring($diff,$Sub->user));

在 Mail\NotifyUserExpiring 中:-

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class NotifyUserExpiring extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
     protected $user;
     protected $diff;
    public function __construct($diff,$user)
    {
        $this->user = $user;
        $this->diff = $diff;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('web.mail.NotifyUserExpiring')->with('user',$this->user)->with('diff',$this->diff);
    }
}

并且在 web.mail.NotifyUserExpiring 查看文件中,我正在使用打印变量的刀片方式:-

Hello {{ $user->first_name }}
Message Here

当我检查我的邮件收件箱时,我收到的电子邮件是准确的 {{ $user->first_name }}

你好 {{ $user->first_name }} 在此留言 我期望当我在邮件视图文件中插入 {{ $user->first_name }} 时,它应该返回用户名。

<div>
    Hello {{ $user->first_name }}

    Message body test
</div>

【问题讨论】:

  • 添加您的web.mail.NotifyUserExpiring 视图的代码。问题似乎在于您呈现数据的方式。

标签: laravel laravel-blade


【解决方案1】:

确保您的邮件视图文件名后缀为.blade.php,以便它通过 Blade 渲染引擎。

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2017-07-27
    相关资源
    最近更新 更多