Laravel 5将Varible从一个功能传递到另一个功能

时间:2015-09-28 02:47:59

标签: laravel-5

我在控制器中的编码:

            $order= Order::find($id);
        $data = array(
            'name' => $order->customer->name,
            'email' => $order->customer->email,
            'no_tel' => $order->customer->no_tel,
            'date'  => Carbon::now('Asia/Kuala_Lumpur'),
        );

        Mail::send('emails.invoice1', $data, function ($message) {
            $message->from('admin@mapdip5b.com', 'Sales');

            $message->to($data['email'], $data['name'])->subject('Your Payment Has Been Accepted');

        });

问题是,如何在Mail :: send方法中传递$数据?

谢谢

1 个答案:

答案 0 :(得分:1)

闭包是功能。功能有自己的范围&#34;所以他们看不到范围之外的变量。您可以使用关键字mTracker = analytics.newTracker(<here>)$data导入闭包范围。尝试:

use