Dav*_*vid 5 php email laravel laravel-5.2
我正在尝试将Beautymail用于我的项目,以便在客户订购东西后发送收据。问题是我在功能中使用Beautymail的方式不像其文档说明状态那样。
这就是我在函数中使用它的方式:
 class OrderController extends Controller {
    public function postOrder(Request $request) {
        // More stuff here, shortned for question purposes
        // Get an instance of the currently authenticated user
        $user = Auth::user();
        // Send email conformation to user that just bought a product or products.
        $beautymail = app()->make(Snowfire\Beautymail\Beautymail::class);
        $beautymail->send('emails.welcome', [], function($message) {
            $message
                ->from('example@admin.com')
                ->to($user->email, $user->username)
                ->subject('Your Receipt');
        });
        // Then return redirect back with success message
        flash()->success('Success', 'Your order was processed successfully. A receipt has been emailed to you');
        return redirect()->route('cart');
    }
}
这是我“结帐”时遇到的错误:
我有什么要补充的吗?我已经完成了composer.json文件,并将其添加到Providers Array中,然后像文档中一样将其发布到Assets文件夹中。
$beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
注意\之前Snowfire\Beautymail\Beautymail::class。
或者,在控制器的顶部:
use Snowfire\Beautymail\Beautymail;
在您的方法中,您可以让Laravel通过IoC容器自动解决它,例如:
public function postOrder(Request $request, Beautymail $beautymail) 
{
    $beautymail->send('emails.welcome', [], function($message) {
    // etc...
}
有关PHP中名称空间的更多信息:
当您引用之外的类时use,您需要声明类是否在全局命名空间中的位置。所以当你有:
app()->make(Snowfire\Beautymail\Beautymail::class);
如果没有前导\,PHP将假定您正在当前名称空间中查找with \App\Http\Controllers。
通过添加开头,\您将告诉PHP类的路径是相对于全局名称空间的。
这是更多信息:http : //php.net/manual/en/language.namespaces.basics.php