Laravel错误-类setEventDispatcher不存在 [英] Laravel error - Class setEventDispatcher does not exist

查看:242
本文介绍了Laravel错误-类setEventDispatcher不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行php artisan serve并访问我的主页时出现此错误:

I'm getting this error, when I run php artisan serve and visit my home page:

ReflectionException (-1)
Class setEventDispatcher does not exist

详细信息

Laravel版本:5.6.39 环境:当地 操作系统:macOS Mojave 10.14.2

Details

Laravel version: 5.6.39 Environment: local OS: macOS Mojave 10.14.2

它开始了,当我在另一个项目中使用npm出现错误时,所以我重新安装了节点(通过这种方式).

It started, when I got an error using npm (in another project), so I reinstalled Node (this way).

执行完此操作后,将无法启动该项目(存在问题).运行php artisan serve时出现此错误:

After doing that, then this project (in question) couldn't be started. I was getting this error, when running php artisan serve:

dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib with anything php related
Referenced from: /usr/local/bin/php
Reason: image not found

该错误已由更新和升级brew 解决.

然后,我有能力启动项目(php artisan serve).但是当我访问主页时,显示此错误:

Then I was capable of starting the project (php artisan serve). But when I visit the home page, this error was shown:

ReflectionException (-1)
Class setEventDispatcher does not exist

如果我遵循堆栈跟踪,那么我可以看到正是这条线(来自我的homeController)触发了错误:

If I follow the stack trace, then I can see that it was this line (from my homeController) that triggered the error:

if( ! Auth::check() ){
  return view( 'pages.home' );
}

如果我将其注释掉,则在使用Auth -module的另一个地方也会发生相同的错误.

If I commented that out, then the same error occured from another place, where the Auth-module was being used.

这是堆栈跟踪:

有人知道如何解决这个问题吗?我在Google上找不到任何有希望的结果,而且我也不知道为什么会这样...:-/

Does anyone know how to resolve this? I can't find any promising results on Google, - and I have no idea why this happens... :-/

我尝试了composer clear-cache并删除了供应商文件夹,然后执行了composer install,问题仍然出现.

I tried composer clear-cache and deleting the vendor-folder, and then doing a composer install and the problem still occured.

我也按照Marcus的建议检查了我的服务提供商-但我真的不知道在那儿寻找什么.一切看起来都很规律(没有花哨的if陈述或其他内容).

I also checked my Service Providers, as Marcus suggested, - but I don't really know what to look for in there. It all looks pretty regular (no fancy if-statements or anything).

我意识到,我无法使用Sequel Pro连接到数据库.这是因为Brew将我的MySQL版本从5.5更新到了8.0.

I realized, that I couldn't connect to my database using Sequel Pro. And it was because Brew had updated my MySQL-version from 5.5 to 8.0.

这是通过按照以下方式进行 来解决的(我做了很多事情,所以我可能会错过很多步骤):

That was resolved by doing something along these lines (I did a bunch of stuff, so I might be missing a coulple of steps):

brew unlink mysql
brew install mysql@5.7
brew switch mysql 5.7.21
brew link mysql

,然后我可以使用mysql --version验证版本.该MySQL版本更改也存在一些权限问题,但是我正在发出该消息,因此不会太长.

and I could then verify the version with mysql --version. I also had some permission issues with that MySQL-version-change, but I'm emitting that, so this doesn't get too long.

我尝试禁用 Laravel调试栏(通过将其从composer.json中删除,删除composer.lockvendor,然后运行composer install).这样就解决了! ... 但!

I tried disabling the Laravel Debugbar (by deleting it from composer.json, deleting composer.lock and vendor and then running composer install). And that fixed it!! ... But!

后来我尝试安装Barryvdh的 IDE帮助器,然后安装完全相同的错误又回来了!!?

When I later tried to install Barryvdh's IDE Helper, then the exact same error came back!?

我执行了以下三个步骤,以安装IDE Helper(并重新引入该错误):

I performed these three steps, to install the IDE Helper (and re-introduce the error):

  1. 从我的目录的根目录运行此命令:curl https://gist.githubusercontent.com/barryvdh/5227822/raw/4be028a27c4ec782965bb8f2fdcb4c08c71a441d/_ide_helper.php -o _ide_helper.php

将这些行添加到app/Provider/AppServiceProvider.php:

...

if ($this->app->environment() !== 'production') {
  $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}

  1. 运行此命令:composer require --dev barryvdh/laravel-ide-helper

所以我回到了这个错误:

So I'm back at this error:

ReflectionException (-1)
Class setEventDispatcher does not exist

...堆栈跟踪与先前显示的相同(从Container.php弹出).

... The stack trace is identical to the one shown previously (sprung from Container.php).

推荐答案

尝试了每个解决方案,但没有一个起作用.

Tried every solution, none of them worked.

最后,我意识到,尝试将php升级到7.3.3时,实际上是导致失败的网络错误.阅读日志,再次尝试,重新启动代客服务,然后再次尝试.

Finally, i realised that when trying to upgrade php to 7.3.3 it was infact a network error that caused the fail. Read the logs, tried again, restarted valet and tried again.

现在可以使用.

升级到7.3.3确实是解决方案.

Upgrading to 7.3.3 was the solution indeed.

谢谢!

这篇关于Laravel错误-类setEventDispatcher不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆