Update AdminController.php

This commit is contained in:
Julian Prieber 2023-12-25 13:21:15 +01:00
parent 522e5f9d21
commit 075f3600f3
1 changed files with 18 additions and 2 deletions

View File

@ -166,9 +166,25 @@ public function SendTestMail(Request $request)
return implode('', $pieces); return implode('', $pieces);
} }
$names = User::pluck('name')->toArray();
$adminCreatedNames = array_filter($names, function($name) {
return strpos($name, 'Admin-Created-') === 0;
});
$numbers = array_map(function($name) {
return (int) str_replace('Admin-Created-', '', $name);
}, $adminCreatedNames);
$maxNumber = !empty($numbers) ? max($numbers) : 0;
$newNumber = $maxNumber + 1;
$domain = parse_url(url(''), PHP_URL_HOST);
$domain = ($domain == 'localhost') ? 'example.com' : $domain;
$user = User::create([ $user = User::create([
'name' => 'Admin-Created-' . random_str(8), 'name' => 'Admin-Created-' . $newNumber,
'email' => random_str(8) . '@example.com', 'email' => strtolower(random_str(8)) . '@' . $domain,
'password' => Hash::make(random_str(32)), 'password' => Hash::make(random_str(32)),
'role' => 'user', 'role' => 'user',
'block' => 'no', 'block' => 'no',