laravel PHP工匠突然不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32211018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP artisan suddenly doesn't work
提问by DarioBB
I have started to learn Laravel. Until now, everything worked perfectly. I'm following this tutorial and I'm stuck with episode 7.
我已经开始学习 Laravel。到目前为止,一切正常。我正在关注本教程,但我被困在第 7 集。
The problem is that I cannot start artisan anymore. I have tried to install tinker, and I've probably updated artisan so I ended up without artisan and tinker. I am using Linux Ubuntu 12.04 LTS. I have installed everything via command line. After that I tried to run:
问题是我不能再开始工匠了。我尝试安装 tinker,我可能已经更新了 artisan,所以我最终没有 artisan 和 tinker。我正在使用 Linux Ubuntu 12.04 LTS。我已经通过命令行安装了所有东西。之后我尝试运行:
php artisan --version
php 工匠 --version
The following problem occurs:
出现以下问题:
[ErrorException]
Declaration of App\Providers\EventServiceProvider::boot() should be compati ble with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
()
[ErrorException]
App\Providers\EventServiceProvider::boot() 的声明应该与 Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
()兼容
This is how my file app/Providers/EventServiceProvider.php
looks like:
这是我的文件的app/Providers/EventServiceProvider.php
样子:
<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\SomeEvent' => [
'App\Listeners\EventListener',
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}
I'm using Laravel 5.2 and my composer.json it looks like this:
我正在使用 Laravel 5.2 和我的 composer.json 它看起来像这样:
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"doctrine/dbal": "^2.6@dev",
"vluzrmos/tinker": "dev-master",
"moon/artisan": "dev-master"
I've seen similar problems here for example:
例如,我在这里看到了类似的问题:
https://laracasts.com/discuss/channels/laravel/event-service-provider-in-package
https://laracasts.com/discuss/channels/laravel/event-service-provider-in-package
but never the answer was given directly and actually I do not understand how to solve this problem? I would need direct answer because I'm newbie in Laravel. Can artisan be updated somehow easy with Linux command line so it can work again?
但从来没有直接给出答案,实际上我不明白如何解决这个问题?我需要直接回答,因为我是 Laravel 的新手。可以使用 Linux 命令行轻松更新工匠,以便它可以再次工作吗?
回答by greut
Apparently, the new boot()
method doesn't take any argument. You'll have to apply some changes to the three providers.
显然,新boot()
方法没有任何参数。您必须对三个提供程序应用一些更改。
/**
* Register any other events for your application.
*
- * @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
- public function boot(DispatcherContract $events)
+ public function boot()
{
- parent::boot($events);
+ parent::boot();
//
}
Check out this commit for the full list of changes.
查看此提交以获取完整的更改列表。
https://github.com/laravel/laravel/commit/2b05ce3b054593f7622c1be6c4c6aadc1c5a54ae
https://github.com/laravel/laravel/commit/2b05ce3b054593f7622c1be6c4c6aadc1c5a54ae
回答by cytsunny
Similar to @greut answer, but if it is caused by upgrading laravel (which may be triggered if you are installing other package through composer update
and your version for laravel is dev-master
), there are 2 places that you need to change the parameter.
与@greut 的回答类似,但如果是升级laravel 引起的(如果你正在安装其他包,composer update
并且你的laravel 版本是dev-master
),则有2 个地方需要更改参数。
App\Providers\RouteServiceProvider
App\Providers\EventServiceProvider
In both controller, there is a method named boot()
. Change the parameter to empty. i.e.
在这两个控制器中,都有一个名为 的方法boot()
。将参数更改为空。IE
public function boot(/*original something here. empty it*/)
{
parent::boot(/*original something here. empty it*/);
}
参考:https: //laracasts.com/discuss/channels/forge/laravel-53-update-causing-error-on-forge-only/replies/189654
回答by MM2
I encountered the same problem in forge while performing the upgrade to 5.3, you need to get rid of bootstrap/cache and as you mentioned artisan won't launch because of that error so you need to do it the old way: rm -R bootstrap/cache
and then mkdir bootstrap/cache
. Don't forget to apply the correct permissions of bootstrap/cache after you're done.
我在执行升级到 5.3 时在 forge 中遇到了同样的问题,您需要摆脱引导程序/缓存,正如您提到的,由于该错误,artisan 不会启动,因此您需要以旧方式执行此操作:rm -R bootstrap/cache
然后mkdir bootstrap/cache
. 完成后不要忘记应用引导程序/缓存的正确权限。
回答by Alan Storm
Speaking strictly from a PHP point of view, when artisan tries to start up its CLI application, and you get this error
严格来说,从 PHP 的角度来看,当 artisan 尝试启动其 CLI 应用程序时,您会收到此错误
Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
App\Providers\EventServiceProvider::boot() 的声明应该与 Illuminate\Foundation\Support\Providers\EventServiceProvider::boot 兼容
You've defined a class App\Providers\EventServiceProvider
. This class has Illuminate\Foundation\Support\Providers\EventServiceProvider
as an parent/ancestor (aliased as ServiceProvider
in your class).
您已经定义了一个类App\Providers\EventServiceProvider
。这个班级有Illuminate\Foundation\Support\Providers\EventServiceProvider
一个父母/祖先(ServiceProvider
在你的班级中别名)。
The boot method in yourIlluminate\Foundation\Support\Providers\EventServiceProvider
has a set of arguments. You have defined boot
in App\Providers\EventServiceProvider
, and changed those arguments somehow (fewer arguments, different type hints, different/no defaults, etc.).
在引导方法您Illuminate\Foundation\Support\Providers\EventServiceProvider
有一组参数。您已boot
在 中定义App\Providers\EventServiceProvider
并以某种方式更改了这些参数(更少的参数、不同的类型提示、不同/无默认值等)。
You can't do that.
你不能那样做。
Make you boot
compatible with the parent class, and you'l fix your problem.
让你boot
与父类兼容,你就会解决你的问题。
(This, however, might not fix all your problems, as the comments make it sound like you're using an unreleased version of Laravel that may differ from what's in a tutorial)
(然而,这可能无法解决您的所有问题,因为评论听起来像是您使用的是未发布的 Laravel 版本,该版本可能与教程中的版本有所不同)