我还是 Laravel 5.1 的新手,但我发现文档非常奇怪和令人困惑。
例如 - 根据 Laravel 文档,我可以使用 Mail 外观中的 send() 方法来发送电子邮件。
到目前为止,一切都很好。当我去 Laravel API 并找到 Illuminate Support Facades Mail 这样的方法不存在? https://laravel.com/api/5.1/Illuminate/Support/Facades/Mail.html
我如何了解该方法采用哪些参数以及成功/失败时返回什么?
最佳答案
那是因为它使用的是Facade模式。
在您的 app.php
配置文件中,有一个名为“别名”的部分。该部分中有一行: 'Mail' => Illuminate\Support\Facades\Mail::class,
指向 Facade,它返回外观的 key
绑定(bind)在服务容器 (IoC)
中,返回要使用的类/对象。
所以你需要找到创建绑定(bind)的地方。绑定(bind)是通过 App::bind('foo', .. )
、App::singleton('foo', .. )
或 App 创建的::instance('foo', ..)
.
我搜索'mailer'
并找到了创建绑定(bind)的文件lluminate\Mail\MailServiceProvider
:
$this->app->singleton('mailer', function($app) {
...
// this is the class resolved by the IoC.
$mailer = new Mailer(
$app['view'], $app['swift.mailer'], $app['events']
);
...
return $mailer;
});
如您所见,\Illuminate\Mail\Mailer
类在服务提供者
中返回,这是您使用Facade 时使用的类
称为邮件
。
发现外观背后的类的快速方法:
您还可以通过转储类名来快速找到类名:dd( get_class( Mail::getFacadeRoot() ) );
更多信息
关于php - Laravel 5.1 Mail 文档 - 令人困惑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851009/