Laravel“工匠制作:观察者”失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28262480/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:48:00  来源:igfitidea点击:

Laravel "artisan make:observer" fails

phplaravellaravel-4artisan

提问by Owen

I am trying to generate a provider using Artisan as described on the documentation page [1] by running:

我正在尝试使用 Artisan 生成提供程序,如文档页面 [1] 中所述,通过运行:

    php artisan make:observer AdServiceProvider

However I get the following error:

但是我收到以下错误:

[InvalidArgumentException] There are no commands defined in the "make" namespace.

[InvalidArgumentException] 在“make”命名空间中没有定义命令。

Am I doing something wrong or is the documentation perhaps outdated?

我做错了什么还是文档可能已经过时了?

http://laravel.com/docs/master/providers

http://laravel.com/docs/master/providers

回答by baao

There is no make:observer command, neither in the documentation, nor in the command list.

文档和命令列表中都没有 make:observer 命令。

As you have tagged your question you are using Laravel 4, there is no make:*** command whatsoever.

由于您标记了您使用的是 Laravel 4 的问题,因此没有任何 make:*** 命令。



For Laravel 5:

对于 Laravel 5:

To create a new provider, simply call

要创建一个新的提供者,只需调用

php artisan make:provider [provider name]

You can always get a list with all commands available by typing

您始终可以通过键入获得包含所有可用命令的列表

php artisan

回答by Dipendra Gurung

Laravel version 5.6has recently introduced the artisan command to create an observer.

Laravel 5.6 版最近引入了 artisan 命令来创建观察者。

You can now issue command like,

你现在可以发出这样的命令,

php artisan make:observer UserObserver --model=User

Check the updated documentation here:- https://laravel.com/docs/5.6/eloquent#observers

在此处查看更新的文档:- https://laravel.com/docs/5.6/eloquent#observers