make:command 未在 Laravel 5.1.7 中定义

make:command not defined in Laravel 5.1.7

我正在尝试使用 make:console 创建调度程序,但它正在返回:

  [InvalidArgumentException]              
  Command "make:console" is not defined. 
  Did you mean one of these?       
     make:seeder                         
     make:migration   

如果这是 5.0 之前的版本就足够了,但我目前使用的是 5.1.7。什么可能导致此问题?

这是当前可用命令的列表:

  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  serve               Serve the application on the PHP development server
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 db
  db:seed             Seed the database with records
 make
  make:migration      Create a new migration file
  make:seeder         Create a new seeder class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:subscribe     Subscribe a URL to an Iron.io push queue
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 schedule
  schedule:run        Run the scheduled commands

如果我将 composer.json 修改为 5.2 版。* 我会收到更精简的命令选择:

  help              Displays help for a command
  list              Lists commands
  migrate           Run the database migrations
 cache
  cache:clear       Flush the application cache
 db
  db:seed           Seed the database with records
 make
  make:migration    Create a new migration file
 migrate
  migrate:install   Create the migration repository
  migrate:refresh   Reset and re-run all migrations
  migrate:reset     Rollback all database migrations
  migrate:rollback  Rollback the last database migration
  migrate:status    Show the status of each migration
 queue
  queue:failed      List all of the failed queue jobs
  queue:flush       Flush all of the failed queue jobs
  queue:forget      Delete a failed queue job
  queue:listen      Listen to a given queue
  queue:restart     Restart queue worker daemons after their current job
  queue:retry       Retry a failed queue job
  queue:work        Process the next job on a queue
 schedule
  schedule:run      Run the scheduled commands

我找到了解决方法。即使我的 Laravel CLI 缺少前面提到的命令,我仍然可以操作调度和命令文件结构。

Commands目录中手动创建example_scheduled_command.php并在Kernal.php中注册。然后,您可以将其用于 Laravel 日程安排。

我遇到了同样的问题,但我可以使用

解决它
php artisan make:console AssignUsers --command=users:assign

然后在app/Console/Kernel中注册命令。php

参见:https://laravel.com/docs/5.0/commands

尝试

php artisan make:command nameCommand

到运行它: 试试 php artisan nameCommand

我不知道为什么,但是我和“schedule:work”有同样的问题,我通过手动将它添加到app/console/kernel来解决它。php

protected $commands = [
    Illuminate\Console\Scheduling\ScheduleWorkCommand::class
]

Illuminate 文件夹中有很多可用的命令,但在“artisan 列表”中没有显示