php - Laravel 5.1 Mail 文档 - 令人困惑?

标签 php email laravel

我还是 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() ) );

更多信息

  • 有关服务容器的更多信息:Click!
  • 有关 Laravel 5 中外观的更多信息:Click!
  • 有关外观模式的更多信息:Click!

关于php - Laravel 5.1 Mail 文档 - 令人困惑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851009/

相关文章:

php - SMTP -> 错误 : Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (0)

c# - hotmail无法连接到远程服务器

php - 在 PHP 中轻松解析持续时间

php - 无法在 Laravel 中发送邮件

javascript - 在点击数据库中的网站时在 iframe 中加载点击 ID 的网站

php - laravel 使用多个数据库,查询语法

php - 拉拉维尔。在一个 POST 方法中更新两个表

mysql - 寻找正确的查询

php - 从 PHP 中的 XML 文件中获取表格的特定行

javascript - Ajax Post 请求失败