I just started working on an artisan command which outputs "hello" every minute with the Laravel task schedular.
My command 'php artisan DeleteInActiveEvents:deleteevents' outputs what is should in the terminal: "hello".
My Command:
class deleteInActiveEvents extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'DeleteInActiveEvents:deleteevents';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
echo "hello";
}
My Kernel.php
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\einkdisplay\Console\Commands\DeleteInActiveEvents::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('DeleteInActiveEvents:deleteevents')->everyMinute();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
So everything is still working at this point. But I want to do this command every minute. When I run php artisan schedule:run it is not running the command. The laravel docs say that I need to add:
php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
to my crontab. But when I use crontab -e in the terminal I'm not getting my crontab and I cannot add this line of code.
My best guess is that you don't have permission to save crontab. Have you try to sudo crontab -e
.