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


PHP User::firstOrNew方法代碼示例

本文整理匯總了PHP中App\Model\User::firstOrNew方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::firstOrNew方法的具體用法?PHP User::firstOrNew怎麽用?PHP User::firstOrNew使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在App\Model\User的用法示例。


在下文中一共展示了User::firstOrNew方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createOrFindUser

 /**
  * @param \Laravel\Socialite\Contracts\User $login
  * @return User
  */
 private function createOrFindUser($login)
 {
     $user = User::firstOrNew(['email' => $login->getEmail()]);
     if ($user->exists) {
         return $user;
     }
     $user->name = $login->getName() ?: $login->getNickname();
     $user->nickname = $login->getNickname();
     $user->password = Hash::make($login->getId() . time());
     $user->avatar = $login->getAvatar();
     $user->admin = User::count() == 0;
     $user->save();
     return $user;
 }
開發者ID:dzirg44,項目名稱:dogpro,代碼行數:18,代碼來源:AuthController.php

示例2: profilePost

 public function profilePost(Request $request, $username)
 {
     $user = User::firstOrNew(['username' => $username]);
     $isOwn = $this->user && $this->user->id === $user->id;
     $isAdmin = $this->user && $this->user->isAdmin();
     if (!$isOwn && !$isAdmin) {
         return redirect('users/' . $this->user->username);
     }
     $user->username = $request->input('username');
     $user->name = $request->input('name');
     $user->email = $request->input('email');
     if ($request->input('password') !== $request->input('password_confirmation')) {
         $this->alert('warning', 'Your passwords did not match. Not changed.');
     } else {
         $user->password = bcrypt($request->input('password'));
     }
     $user->save();
     // Roles.
     if ($isAdmin && $request->input('roles')) {
         $user->roles()->sync($request->input('roles'));
     }
     // Save unavailabilities.
     \DB::table('user_unavailabilities')->where('user_id', '=', $user->id)->delete();
     foreach ($request->input('unavailabilities') as $unavail) {
         if (empty($unavail['start_date']) && empty($unavail['end_date'])) {
             continue;
         }
         $unavailability = new \App\Model\UserUnavailability();
         $unavailability->user_id = $user->id;
         $unavailability->start_date = $unavail['start_date'];
         $unavailability->end_date = $unavail['end_date'];
         $unavailability->save();
     }
     $this->alert('success', 'User profile information saved.');
     return redirect('users');
 }
開發者ID:samwilson,項目名稱:asset-manager,代碼行數:36,代碼來源:UsersController.php


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