【发布时间】:2019-08-30 21:52:02
【问题描述】:
我已经创建了简单的包,这里是我的目录结构并使用 laravel 5.4
├── composer.json
└── src
├── ArtisanTestmeServiceProvider.php
└── Commands
└── TestmeCommand.php
我的问题是,我的自定义命令未在 artisan (php artisan) 中列出
这里是TestMeCommand.php
的源代码<?php
namespace TestMe\Commands;
use Illuminate\Console\Command;
class TestmeCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'testme:run';
/**
* The console command description.
*
* @var string
*/
protected $description = 'lorem ipsum';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$this->info("Version : test test");
}
}
这里是 ServiceProvider ArtisanTestmeServiceProvider
<?php
namespace TestMe\Commands;
use Illuminate\Support\ServiceProvider;
class ArtisanTestmeServiceProvider extends ServiceProvider
{
protected $commands = [
'robyfirnandoyusuf\TestMe\Commands\TestmeCommand',
];
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->commands($this->commands);
}
}
以下是我的包中的composer.json
{
"name": "robyfirnandoyusuf/lara-testme",
"description": "test",
"license": "MIT",
"authors": [
{
"name": "Roby Firnando Yusuf",
"email": "idonthave@gmail.com"
}
],
"minimum-stability": "dev",
"require": {},
"autoload" : {
"psr-4":{
"TestMe\\": "src/"
}
},
"extra":{
"laravel":{
"providers":[
"TestMe\\Commands\\ArtisanTestmeServiceProvider"
]
}
}
}
在 composer.json on laravel 项目,我已被添加:
"repositories":[
{
"type": "path",
"url": "../Packagistku/TestPackage/"
}
],
我是否错过了一些东西,以至于我的自定义命令未列在 artisan command 中?
【问题讨论】:
-
可能是由于这里的命令数组中的单引号:
'robyfirnandoyusuf\TestMe\Commands\TestmeCommand'只需删除它并尝试 -
我改成双引号并去掉引号但还是没有列出...
-
我的意思是不要添加任何报价 ;)
-
还是不行……
-
如果你运行命令 php artisan testme:run 它是否工作?
标签: php laravel laravel-5 package