本文整理汇总了PHP中RainLab\User\Models\User::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP User::firstOrNew方法的具体用法?PHP User::firstOrNew怎么用?PHP User::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
* @return void
*/
public function fire()
{
$this->output->writeln('Hello world!');
$crmusers = CRMUser::isNotUpdated()->isHaveEmail()->get();
echo "Processing Users: \n";
$crmusers->each(function ($user) {
$validator = \Validator::make(['email' => $user->email], ['email' => 'email']);
if ($validator->fails()) {
echo $user->email . " not valid email! [-]" . "\n";
} else {
$cmsuser = CMSUser::firstOrNew(['username' => $user->email]);
echo $user->email . " ";
$cmsuser->fill($user->toArray());
if (!$cmsuser->is_activated) {
$pass = str_random(12);
$cmsuser->password = $pass;
$cmsuser->password_confirmation = $pass;
echo ": " . $pass;
}
$user->is_updated = true;
$user->save();
$cmsuser->save();
if (!$cmsuser->is_activated) {
$code = implode('!', [$cmsuser->id, $cmsuser->getActivationCode()]);
$link = Page::url('personal', ['code' => $code]);
$data = ['name' => $cmsuser->name, 'link' => $link, 'code' => $code];
Mail::send('abnmt.mrc::mail.activate', $data, function ($message) use($cmsuser) {
$message->to($cmsuser->email, $cmsuser->name);
});
}
// if (!$cmsuser->is_activated) {
// try { $cmsuser->attemptActivation($cmsuser->activation_code);} catch (\Exception $e) {echo " EXCEPTION!";}
// }
// \Mail::sendTo($this, 'backend::mail.invite', [
// 'name' => $user->name,
// 'email' => 'mrc@abnmt.com',
// 'password' => $pass,
// ]);
echo " [+]\n";
}
});
echo "\n";
$cmsusers = CMSUser::count();
// echo "\n";
// print_r($crmusers);
// echo "\n";
// print_r($cmsusers);
// echo "\n";
}
示例2: onUpdateFromCrm
/**
* Update Courses from CRM
*/
public function onUpdateFromCrm()
{
$crmusers = CRMUser::isNotUpdated()->isHaveEmail()->get();
if (count($crmusers) == 0) {
Flash::info("No Users for Create/Update");
return;
// return ['#flashMessages' => $this->makePartial('message', ['messages' => ['Success']])];
}
$messages = [];
$crmusers->each(function ($user) use(&$messages) {
$validator = \Validator::make(['email' => $user->email], ['email' => 'email']);
if ($validator->fails()) {
$messages[] = "[–] " . $user->email . " not valid email!";
} else {
$cmsuser = User::firstOrNew(['username' => $user->email]);
$cmsuser->fill($user->toArray());
if (!$cmsuser->is_activated) {
$pass = str_random(12);
$cmsuser->password = $pass;
$cmsuser->password_confirmation = $pass;
$messages[] = "[+] " . $user->email . ' ' . $pass ?: '';
} else {
$messages[] = "[^] " . $user->email;
}
$user->is_updated = true;
$user->save();
$cmsuser->save();
if (!$cmsuser->is_activated && is_null($cmsuser->activation_code)) {
$code = implode('!', [$cmsuser->id, $cmsuser->getActivationCode()]);
$link = Page::url('profile/activate', ['code' => $code]);
$data = ['name' => $cmsuser->name, 'link' => $link, 'code' => $code];
Mail::send('abnmt.mrc::mail.activate', $data, function ($message) use($cmsuser) {
$message->to($cmsuser->email, $cmsuser->name);
});
}
}
});
Flash::success("Users is update");
return ['#flashMessages' => $this->makePartial('message', ['messages' => $messages])];
}