Skip to content

Commit 9bf8ca0

Browse files
committed
✨ create publish command
1 parent aadbd9a commit 9bf8ca0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Article;
6+
use Illuminate\Console\Command;
7+
8+
class PublishArticles extends Command
9+
{
10+
protected $signature = 'lcm:publish-articles';
11+
12+
protected $description = 'Published all articles already submitted and approved';
13+
14+
public function handle(): void
15+
{
16+
$this->info('Published all submitted articles...');
17+
18+
$articles = Article::submitted()->approved()->whereNull('published_at')->get();
19+
20+
foreach ($articles as $article) {
21+
$article->published_at = $article->submitted_at;
22+
$article->save();
23+
}
24+
25+
$count = $articles->count();
26+
27+
$this->comment("Published {$count} articles.");
28+
29+
$this->info('All done!');
30+
}
31+
}

0 commit comments

Comments
 (0)