Initial commit
This commit is contained in:
50
app/Console/Commands/RegisterPostsAsReactants.php
Normal file
50
app/Console/Commands/RegisterPostsAsReactants.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Post;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RegisterPostsAsReactants extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'posts:register-reactants';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Register all existing posts as Love reactants';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Registering posts as Love reactants...');
|
||||
|
||||
$posts = Post::all();
|
||||
$registered = 0;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($posts as $post) {
|
||||
if (!$post->isRegisteredAsLoveReactant()) {
|
||||
$post->registerAsLoveReactant();
|
||||
$registered++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Registered {$registered} posts as reactants.");
|
||||
$this->info("Skipped {$skipped} posts (already registered).");
|
||||
$this->info('Done!');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user