There are no commands defined in the "command" namespace. I have created some commands in my application and I registered them in Console/Commands/Kernel.php
protected $commands = [
Commands\ClearNotificationsTable::class,
Commands\ClearTasksFromNotifications::class,
];
Yet when I try to execute them via artisan php artisan command:ClearNotificationsTable I get the following error.
"There are no commands defined in the "command" namespace."
The command files are all located in Console/Commands
Any ideas?
You execute Artisan commands using the name you specify in the Command class.
Ya that's what I am doing.
php artisan command:ClearNotificationsTable
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ClearNotificationsTable extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:ClearNotificationsTable';
If you run php artisan list, do you see your commands in the output?
Also, you do not have to manually register the commands if they are inside the App\Console\Commands namespace already - they are automatically registered by default.
Did you create the commands via...
php artisan make:command --command=command:ClearNotificationsTable
I did a test with the same naming in 5.5 and it worked fine... just curious if the command is not in the correct directory.
@tykus No they do not. Which is odd.
@mfoote I believe I did it as
php artisan make:command ClearNotificationsTable
They are located in App\Console\Commands
Can you show us your entire kernel file?
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\ClearTasksFromNotifications::class,
Commands\ClearNotificationsTable::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('command:ClearNotificationsTable')
->weekly()->mondays()->at('08:00');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
Or you can add in appServiceProvider class as:
$this->commands([
JobNotificationSendCommand::class
]);
Can you show the full command? There might be a syntax error making the file unreadable
Please sign in or create an account to participate in this conversation.