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.
CodePudding user response:
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
CodePudding user response:
You should create a Laravel Command. Take you code from the controller and put it there.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
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