【问题标题】:Laravel 5.8 Call to undefined method Illuminate\Events\Dispatcher::fire()Laravel 5.8 调用未定义的方法 Illuminate\Events\Dispatcher::fire()
【发布时间】:2019-04-17 14:32:46
【问题描述】:

我在用户注册时收到此错误。我已经搜索了很多这个问题,但仍然无法解决我这边的问题。在 laravel 5.8 升级中,写入函数 fire() 更改为 dispatch(),但我在我的应用程序的任何文件中都找不到任何 fire() 函数,所以我可以看到发生了什么。

不胜感激。谢谢。

【问题讨论】:

  • 请提供一些代码,以便我们找出实际问题是什么,我们不能仅通过描述来做到这一点。
  • 您好 Hovhannes,作为建议,我建议您查看本指南以便提出清晰完整的问题:How to Ask
  • ibb.co/KmtLLQ1 这是来自我的 RegisterController 的 sn-p,只是在进行常规注册,没什么奇怪的。我在 laravel 从 5.6 升级到 5.8 后开始出现此错误。

标签: laravel laravel-5.8


【解决方案1】:

发件人: https://laravel.com/docs/5.8/events#dispatching-events

代替:

Event::fire(new \App\Events\NewUserSignup($new_user));

改为:

event(new \App\Events\NewUserSignup($new_user));

【讨论】:

    【解决方案2】:

    Illuminate\Events\Dispatcher 类的 fire 方法(在 Laravel 5.4 中已弃用)已被移除 (https://github.com/laravel/framework/pull/26392)。您应该改用 dispatch 方法。

    而不是: Event::dispatch('customer.created', $customer);

    这样做: Event::dispatch('customer.created', $customer);

    或者: event('customer.created', $customer);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-03
      • 2015-11-15
      • 2018-06-25
      • 1970-01-01
      • 2019-11-02
      • 2016-10-22
      • 2019-09-23
      • 1970-01-01
      相关资源
      最近更新 更多