即使我正在注册 Laravel 6.x,也找不到命令

The*_*ebs 0 php laravel laravel-6

所以考虑一下服务提供商,是的,我知道我在两个地方注册了这个命令,但请给我一点时间来解释:

<?php

namespace App\Modules\Core\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Foundation\AliasLoader;
use App\Modules\Core\Handlers\RedirectHandler;
use App\Modules\Core\Console\Commands\CreateAdminUser;
use App\Modules\Core\Values\IsMedicalRecordEmpty;

class CoreProvider extends ServiceProvider
{

    protected $commands = [
        CreateAdminUser::class,
    ];

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(RedirectHandler::class, function($app) {
            return new RedirectHandler();
        });

        $this->app->bind(IsMedicalRecordEmpty::class, function($app) {
            return new IsMedicalRecordEmpty();
        });
    }

    public function register() {
        $this->commands($this->commands);
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->app->runningInConsole()) {
            $this->commands([
                CreateAdminUser::class,
            ]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,作为前面所说,我们可以看到,我在两个地方注册这个命令,因为我试图找出为什么调用php artisan,如果我在注册它不显示命令,那只能说明app\Console\Kernel,而是因为我想取代码库的模块化方法,我想在我的服务提供者中注册它,注册如下:

'providers' => [

    ...

    /**
     * Module Related Providers
     */
    App\Modules\Core\Providers\CoreProvider::class,

    ...
],
Run Code Online (Sandbox Code Playgroud)

我正确注册了提供者,我(是的,我知道我不需要两次注册命令)以堆栈解释的方式注册命令,无论哪种方式理论上都应该有效。

但遗憾的是,当我运行php artisan. 在所有。

命令很简单:

<?php

namespace App\Modules\Core\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Illuminate\Auth\Events\Verified;
use App\Modules\Core\Users\Mail\GeneratedAdmin;
use App\Modules\Core\Users\Models\User;
use App\Modules\Core\Users\Services\RegisterUserService;

class CreateAdminUser extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create:admin {first_name} {last_name} {email}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create one admin.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        // do stuff here ...
    }
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Mic*_*ker 10

您的代码正在重新声明register(),首先是在具有绑定的方法中,然后是在您的方法调用中$this->command()- 您是否正确地引用了您的服务提供者?PHP 应该告诉你这一点 - 当我尝试你的示例代码时它对我有用......

 Whoops\Exception\ErrorException  : Cannot redeclare App\Modules\Core\Providers\CoreProvider::register()
Run Code Online (Sandbox Code Playgroud)

值得注意的是,使用绑定删除第一个方法会导致命令为我显示。