I don’t know why my cron job is not running. Even though if I manually run the custom command, it works. This is what the cronjob file looks like when I do crontab -e.
1 * * * * cd /Applications/MAMP/htdocs/projectName/app/console/Commands && php artisan schedule:run >> /dev/null 2>&1
when I run php artisan schedule:run
I get, No scheduled commands are ready to run.
Edit:
This is what my command class looks like:
class deletePics extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'picOfMonth:truncate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete pics from old';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
PicOfMonth::where('created_at', '<', Carbon::now())->each(function ($item) {
$item->delete();
});
}
Also in my Kernel.php it looks like this:
class Kernel extends HttpKernel
{
protected $commands = [
deletePics::class
];
protected function schedule(Schedule $schedule)
{
$schedule->command('picOfMonth:truncate')->everyMinute();
}
Advertisement
Answer
Your schedule commands should be in appConsoleKernel.php and not HttpKernel.php