12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Models\Article;
- class PublishScheduledArticles extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'app:publish-scheduled-articles';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Execute the console command.
- */
- public function handle()
- {
- $pending_up = Article::pending()->get();
- $pending_down = Article::published()->whereNotNull("unpublish_at")->get();
- foreach ($pending_up as $article) {
- if ($article->publish_at->isPast()) {
- $this->info("Publishing [$article->title] at " . now());
- $article->publish();
- }
- }
- foreach ($pending_down as $article) {
- if ($article->unpublish_at->isPast()) {
- $this->info("Taking down [$article->title] at " . now());
- $article->unpublish();
- }
- }
- }
- }
|