Create a trial user in snapforms
Tue Oct 29 2024 23:53:58 GMT+0000 (Coordinated Universal Time)
Saved by
@Themaheshe
$ipAuth = $_SERVER['REMOTE_ADDR'];
$firstName = 'trialMahesh';
$lastName = 'test';
$email = 'maheshtrialnew@gmail.com';
$organisation = htmlspecialchars('mytrialorg');
$phone = htmlspecialchars('0405550505');
$username = $organisation;
$username = mb_strtolower($username);
$username = preg_replace('/[^a-zA-Z]+/', '', $username);
$extraNumber = 1;
while (User::findByUsernameOrAlias($username)) {
$extraNumber++;
preg_match('~^[^-]+~', $username, $matches);
$username = $matches[0].'-'.$extraNumber;
}
$length = 9;
$str = '';
$characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
$max = count($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$rand = mt_rand(0, $max);
$str .= $characters[$rand];
}
$password = 'Mahesh123#';
$expiryDate = Carbon::today()->addDays(31)->format('Y-m-d');
$userDetails = [
'username' => $username,
'email' => $email,
'password' => Hash::make($password),
'phone' => $phone,
'name' => $firstName . ' ' . $lastName,
'organisation' => $organisation,
'plan' => 'trial',
'status' => 'active',
'uuid' => (string) Str::uuid(),
'expiry' => $expiryDate,
];
$user = User::create($userDetails);
$user->createOwnOrganisation();
event(new Registered($user));
$trialFormStatus = new UserTrialFormstatus;
$trialFormStatus->user_id = $user->id;
$trialFormStatus->formstatus = 'good';
$trialFormStatus->save();
$trialDevice = new UserTrialDevice;
$trialDevice->user_id = $user->id;
$trialDevice->device = '127.7.7.1';
$trialDevice->save();
dd($user);
content_copyCOPY
create a trial user
Comments