| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Post;
- use Illuminate\Console\Command;
- class PublishScheduledPosts extends Command
- {
- protected $signature = 'posts:publish-scheduled';
- protected $description = 'Публикация запланированных постов';
- public function handle()
- {
- $posts = Post::readyForPublishing()->get();
-
- if ($posts->isEmpty()) {
- $this->info('Нет постов для публикации');
- return 0;
- }
- foreach ($posts as $post) {
- $post->publish();
- $this->info("Опубликован пост: {$post->title}");
- }
- $this->info("Всего опубликовано постов: {$posts->count()}");
- return 0;
- }
- }
|