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

trying to pass data to the view laravel 5.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('test@test.com', 'Your Application');
        $m->to('test@gmail.com')->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 还是有点陌生​​。

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

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

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

表示直接访问您的变量,而不是通过数组索引访问。