Laravel Mail:未定义的变量$ data

时间:2014-10-31 07:33:52

标签: laravel laravel-4

我的控制器生成此数据数组:

Array
(
    [bothweek] => Array
        (
            [0] => 2014-10-26
            [1] => 2014-10-19
        )

    [projects] => Array
        (
            [0] => stdClass Object
                (
                    [day_name] => Wednesday
                    [project_date] => 2014-10-22
                    [invoiced_date] => 2014-10-31
                    [week_end_day] => 2014-10-26
                    [user_name] => John
                 )
        )
)

但是当我尝试将其发送到邮件刀片时,它无法识别此阵列,有人可以给我一个解决方案,谢谢,

Mail::send('project.mail', $data, function ($message) {
    $message->from('email', 'ABC');

    $message->to('send');

});

1 个答案:

答案 0 :(得分:1)

如果您希望在查看文件$data中访问project.mail,则需要使用['data' => $data]作为第二个参数,否则您将获得两个变量$bothweek$projects

Mail::send('project.mail', ['data' => $data], function ($message) {
    ...
});