trypost/app/Console/Commands/ProcessScheduledPosts.php

27 lines
645 B
PHP
Raw Normal View History

2026-01-15 01:13:44 +00:00
<?php
2026-01-19 00:49:13 +00:00
namespace App\Console\Commands;
2026-01-15 01:13:44 +00:00
2026-01-19 00:49:13 +00:00
use App\Jobs\PublishPost;
2026-01-15 01:13:44 +00:00
use App\Models\Post;
2026-01-19 00:49:13 +00:00
use Illuminate\Console\Command;
2026-01-15 01:13:44 +00:00
2026-01-19 00:49:13 +00:00
class ProcessScheduledPosts extends Command
2026-01-15 01:13:44 +00:00
{
2026-01-19 00:49:13 +00:00
protected $signature = 'posts:process-scheduled';
protected $description = 'Process scheduled posts that are due for publishing';
2026-01-15 01:13:44 +00:00
public function handle(): void
{
Post::query()
->due()
->with(['postPlatforms.socialAccount', 'postPlatforms.media'])
->chunk(100, function ($posts) {
foreach ($posts as $post) {
PublishPost::dispatch($post);
}
});
}
}