SAMPLE HERE I have around seven real users including me 😁
first create a php file like createuser.php in your flarum folder
then paste this inside that php file
`<?php
use Flarum\Foundation\Site;
use Flarum\User\User;
use Illuminate\Support\Str;
require 'vendor/autoload.php';
$site = Site::fromPaths([
'base' => DIR,
'public' => DIR . '/public',
'storage' => DIR . '/storage',
]);
$app = $site->bootApp();
$container = $app->getContainer();
$hash = $container->make('hash');
$userRepo = $container->make(\Flarum\User\UserRepository::class);
$firstNames = [
"Aelindra", "Thorgrim", "Lyralei", "Kaelen", "Seraphina", "Drakemoor", "Elara"
];
$emailProviders = [
'gmail.com', 'yahoo.com', 'outlook.com', 'protonmail.com', 'icloud.com', 'aol.com',
'mail.com', 'gmx.com', 'zoho.com', 'yandex.com', 'tutanota.com', 'inbox.com',
'hotmail.com', 'fastmail.com', 'live.com', 'msn.com', 'rocketmail.com',
'email.com', 'hushmail.com', 'mailfence.com', 'rediffmail.com', 'seznam.cz',
'web.de', 'mail.ru', 'bluewin.ch', 'naver.com', '163.com', 'qq.com', 'daum.net'
];
function generateUnique($names, $emailProviders) {
while (true) {
$username = strtolower($names[array_rand($names)]) . rand(1000, 9999);
$domain = $emailProviders[array_rand($emailProviders)];
$email = $username . '@' . $domain;
$usernameExists = User::where('username', $username)->exists();
$emailExists = User::where('email', $email)->exists();
if (!$usernameExists && !$emailExists) {
return [$username, $email];
}
}
}
for ($i = 0; $i < 500; $i++) {
[$username, $email] = generateUnique($firstNames, $emailProviders);
$password = Str::random(10);
echo "Creating: $username | $email | $password\n";
file_put_contents('users.txt', "$username | $email | $password\n", FILE_APPEND);
$user = User::register($username, $email, $hash->make($password));
$user->activate();
$user->save();
}
`
You can add more names or email providers if you want and change the 500 in this part "($i = 0; $i < 500; $i++)" to set the amount of users you will generate, if you want 10 just put 10.
and then go to your flarum folder
cd /var/www/flarum
then
in this example run php createuser.php
Why do this?
- Setting up staging/demo environments
-
- Populating forums for beta testing
-
- Making your forum look active for new visitors
-
- Stress testing extensions that rely on user activity or ranks