【问题标题】:Call to undefined method Illuminate\Database\Query\Builder::notify()调用未定义的方法 Illuminate\Database\Query\Builder::notify()
【发布时间】:2017-01-13 06:13:44
【问题描述】:

Laravel 5.3.6 在忘记密码中提交请求时出现问题。

错误详情

调用未定义的方法 Illuminate\Database\Query\Builder::notify()

问题在以下文件中:

vendor\laravel\framework\src\Illuminate\Auth\Passwords\PasswordBroker.php

第 69 行。代码如下

$user->sendPasswordResetNotification(
    $this->tokens->create($user)
);

功能:发送重置链接

它在 Laravel 5.2 中运行良好,但在 5.3.6 版本中似乎无法运行。你遇到过这个问题吗?

【问题讨论】:

    标签: php laravel-5.2 laravel-5.1 laravel-5.3


    【解决方案1】:

    您必须在 User 模型中添加 Illuminate\Notifications\Notifiable 特征。

    【讨论】:

    • 出现错误:(1/1) FatalErrorException Trait 'Illuminate\Notifications\Notifiable' 未找到
    【解决方案2】:
    1. 在您的用户模式中添加 Notifiable trait。

      Illuminate\Notifications\Notifiable

    2. 在你的 app.php 中添加这个:

    对于您的提供商:

    Illuminate\Notifications\NotificationServiceProvider::class,

    在别名中:

    'Notification' => Illuminate\Support\Facades\Notification::class,

    1. 记得在 config/mail.php 文件中更新您的 from 设置。

    【讨论】:

      【解决方案3】:

      就我而言,按照其他答案中给出的步骤进行操作后,我仍然遇到错误。

      BadMethodCallException:调用未定义的方法 Illuminate\Database\Query\Builder::notify()

      我错过了

      使用通知

      ...
      use Illuminate\Notifications\Notifiable;
      class User extends Model
      {
           use SoftDeletes, Notifiable;
           ...
      

      【讨论】:

        【解决方案4】:

        为了清楚起见,您必须执行以下所有操作:

        在您的用户模式中添加 Notifiable trait。

        use Illuminate\Notifications\Notifiable;
        
        class User extends Model
        {
             use SoftDeletes, Notifiable;
        

        在你的 app.php 中添加这个:

        对于您的提供商:

        Illuminate\Notifications\NotificationServiceProvider::class,
        

        在别名中:

        'Notification' => Illuminate\Support\Facades\Notification::class,
        

        感谢 Nijesh、Francisco 和 Bestmomo Momo 的部分答案,但我必须完成以上所有工作。

        【讨论】:

          猜你喜欢
          • 2017-12-12
          • 2014-04-23
          • 2020-01-04
          • 2018-10-03
          • 1970-01-01
          • 2019-04-02
          • 2016-11-25
          • 2017-07-19
          • 2017-01-18
          相关资源
          最近更新 更多