paduraruionutandrei
7 months ago

CronJob

Posted 7 months ago by paduraruionutandrei

Hello, I have a cron job who must send an email everyday with some products info.Here is the command.

    class ProductAlert extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'product:alert';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send an email with product stock alert';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $products = DB::table('products')->whereRaw('product_qty  < product_stock_alert')->get();

        Mail::to('[email protected]')->send(new SendMailable($products));
    }
}

KERNEL

    class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
        'App\Console\Commands\ProductAlert',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('product:alert')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

In my local environment it works fine, but when I add it to cpanel, it does not work.

    php /home/ediagnoza/itrack.ediagnoza.ro/artisan schedule:run > /dev/null 2>&1

Thank you so much.

Please sign in or create an account to participate in this conversation.