skip to Main Content

I want to send my articles to my Telegram channel automatically by the date time I have scheduled, so I should use queue or cron job.

I have used queue, so in local development to send notifications to telegram I refresh the webpage, I don’t want it like this, when deployed to production I want it to auto-send when I have scheduled.

2

Answers


  1. I think the cron job will suits best for the scenario, kindly refer the task scheduling from the laravel documentation for the same : https://laravel.com/docs/9.x/scheduling

    Login or Signup to reply.
  2. You should create a Laravel Command. Take you code from the controller and put it there.

    <?php
     
    namespace AppConsoleCommands;
     
    use IlluminateConsoleCommand;
     
    class SendTelegram extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'command:telegram';
      
        protected $description = 'Send a Telegram channel';
     
        
        public function handle()
        {
            /*Here your code*/
        }
    }
    

    Then, add a schedule: app/Console/Kernel.php

    protected function schedule(Schedule $schedule)
        {
            $schedule->command('command:telegram')
                     ->everyMinute();
        }
    

    Finally; using terminal

    php artisan schedule:run
    

    Also, you can create a schedule cron to run your command:telegram

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search