當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::firstOrNew方法代碼示例

本文整理匯總了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";
 }
開發者ID:abnmt,項目名稱:oc-mrc-plugin,代碼行數:53,代碼來源:SyncUsers.php

示例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])];
 }
開發者ID:abnmt,項目名稱:oc-mrc-plugin,代碼行數:43,代碼來源:Users.php


注:本文中的RainLab\User\Models\User::firstOrNew方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。