File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments