some progress: users slugs, bookmarks page, upvotes page, design
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GenerateUserSlugs extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'users:generate-slugs';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate unique slugs for all users without slugs';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Generating slugs for users...');
|
||||
|
||||
$usersWithoutSlugs = User::whereNull('slug')->get();
|
||||
|
||||
if ($usersWithoutSlugs->isEmpty()) {
|
||||
$this->info('All users already have slugs!');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar($usersWithoutSlugs->count());
|
||||
$bar->start();
|
||||
|
||||
foreach ($usersWithoutSlugs as $user) {
|
||||
$user->slug = User::generateUniqueSlug($user->name);
|
||||
$user->save();
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Successfully generated slugs for {$usersWithoutSlugs->count()} users!");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user