试图将数据传递给视图laravel 5.1

问题描述 投票:0回答:1

在这里,我的控制器中有以下内容

    $data = [];

    mt_srand((double)microtime()*15000);//optional for php 4.2.0 and up.
    $charid = strtoupper(md5(uniqid(rand(), true)));
    $uuid = substr($charid, 0, 8)
    .substr($charid, 8, 4)
    .substr($charid,12, 4)
    .substr($charid,16, 4)
    .substr($charid,20,12);

    $data['confirmation_link'] = $uuid;
    //dd($data);
    Mail::send('email.test', $data, function ($m) {
        $m->from('[email protected]', 'Your Application');
        $m->to('[email protected]')->subject('Your Reminder!');
    });

这是我的看法

<p>
  This is a test, an email test.
</p>
<p>
  The variable <code>$data['confirmation_link']</code> contains the value:
</p>
<ul>
  <li><strong>{{ $data['confirmation_link'] }}</strong></li>
</ul>
<hr>
<p>
  That is all.
</p>

但我收到错误信息

Undefined variable: data 

我没有正确地将数据传递给视图吗?我正在传递一个数组。我仍然是MVC框架的新手,并与OOP合作。

laravel laravel-5 laravel-blade
1个回答
1
投票

您不需要访问变量,因为array index只是在您的视图中执行此操作

写这个$confirmation_link而不是$data['confirmation_link']

The variable <code>$confirmation_link</code> contains the value:

意味着直接访问您的变量而不是通过数组索引访问。

© www.soinside.com 2019 - 2024. All rights reserved.