| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Models\Post;
- class PublishScheduledPosts extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'blog:publish-scheduled';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Публикация отложенных статей';
- /**
- * Execute the console command.
- */
- public function handle()
- {
- //
- $count = Post::where('is_published', false)
- ->whereNotNull('scheduled_at')
- ->where('scheduled_at', '<=', now())
- ->update([
- 'is_published' => true,
- 'published_at' => now()
- ]);
- $this->info("Опубликовано статей: " . $count);
- }
- }
|