You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pixelfed/app/Console/Commands/SeedDevUsers.php

73 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class SeedDevUsers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'seed:devusers';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seed dev users (admin + regular) with random passwords';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = [
[
'name' => 'Admin User',
'username' => 'admin',
'email' => 'admin@example.com',
'is_admin' => true,
],
[
'name' => 'Test User',
'username' => 'user',
'email' => 'user@example.com',
'is_admin' => false,
],
];
foreach ($users as $data) {
if (User::whereUsername($data['username'])->exists()) {
$this->warn("User '{$data['username']}' already exists, skipping.");
continue;
}
$password = Str::random(16);
$user = User::factory()->create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($password),
'is_admin' => $data['is_admin'],
'email_verified_at' => now(),
]);
$role = $data['is_admin'] ? 'admin' : 'user';
$this->info("Created {$role}: {$data['username']} / {$data['email']} — password: {$password}");
}
$this->newLine();
$this->info('Done! Save these passwords — they are generated randomly each run.');
}
}