Source path: app/Console/Commands/DispatchDuePosts.php
Extracted from supplied specification. Review before copying into application.

<?php
namespace App\Console\Commands;

use App\Jobs\PublishToPlatform;
use App\Models\Post;
use Illuminate\Console\Command;

class DispatchDuePosts extends Command
{
    protected $signature = 'posts:dispatch-due';
    protected $description = 'Dispatch scheduled posts whose time has come';

    public function handle(): int
    {
        Post::where('status', 'scheduled')
            ->where('scheduled_at', '<=', now())
            ->with('targets')
            ->each(function (Post $post) {
                if (!$post->mediaReady()) {
                    return; // AI media still generating; try again next minute
                }
                $post->update(['status' => 'publishing']);
                foreach ($post->targets as $target) {
                    PublishToPlatform::dispatch($target);
                }
            });

        return self::SUCCESS;
    }
}
