this is my cron job command in cloudway server:
* * * * * php /home/1432345-6789110.cloudwaysapps.com/pedisfdfdsddd/public_html/artisan schedule:run >> /dev/null 2>&1
The cron did run every minute, but it does NOT execute the command. If i type the php artisan command manually: php artisan command:name --> it work.
Below is my kernel.php and customCommand.php kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
Commands\CustomCommand::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('custom:command')->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
customCommand.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class CustomCommand extends Command
{
protected $signature = 'command:name';
protected $description = 'Delete all read notifications after 3 days';
public function __construct()
{
parent::__construct();
}
public function handle()
{
DB::table('notifications')
->whereIn('type', ['App\Notifications\WeeklyReader', 'App\Notifications\WeeklyFile'])
->where([
['created_at', '<=', \Carbon\Carbon::now()->subDays(3)->toDateTimeString()],
['read_at', '!=', 'null'],
])
->delete();
$this->info('All notifications are deleted successfully!');
}
}