当前位置: 首页>>代码示例>>PHP>>正文


PHP User::firstOrCreate方法代码示例

本文整理汇总了PHP中App\Model\User::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP User::firstOrCreate方法的具体用法?PHP User::firstOrCreate怎么用?PHP User::firstOrCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在App\Model\User的用法示例。


在下文中一共展示了User::firstOrCreate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getParamsTwig

 /**
  * @param array $params
  * @param null $request
  * @return array
  */
 private function getParamsTwig($params = array(), $request = null)
 {
     if ($this->loginUrlOrGraphUser instanceof GraphUser) {
         $graphUser = $this->loginUrlOrGraphUser;
         // Create and update user
         $user = User::firstOrCreate(['facebook_id' => $graphUser->getId()]);
         if (!$user instanceof User) {
             $user = new User();
             $user->facebook_id = $graphUser->getId();
         }
         $user->gender = $graphUser->getGender() == 'male' ? 'M.' : 'Mme';
         $user->email = $graphUser->getEmail();
         $user->first_name = $graphUser->getFirstName();
         $user->last_name = $graphUser->getLastName();
         $user->save();
     }
     $configFacebook = $this->config['facebook'];
     return array_merge(['APP_ID' => $configFacebook['id'], 'URL_WEB_APP' => $configFacebook['url'], 'user' => isset($graphUser) ? $graphUser : null], $params);
 }
开发者ID:Janoski,项目名称:futurtravel,代码行数:24,代码来源:AppController.php

示例2: loginPost

 public function loginPost(Request $request)
 {
     $username = $request->input('username');
     $request->session()->set('username', $username);
     $password = $request->input('password');
     $returnTo = url($request->input('return_to', ''));
     // Try to log in.
     if (Auth::attempt(['username' => $username, 'password' => $password])) {
         $this->alert('success', 'You are now logged in.', true);
         return redirect($returnTo);
     }
     // If that fails, try Adldap.
     $adldapConfig = config('adldap');
     if ($adldapConfig['enabled']) {
         $adldap = new \Adldap\Adldap($adldapConfig);
         if (empty($adldap->getConfiguration()->getAdminUsername())) {
             $adldap->getConfiguration()->setAdminUsername($username);
             $adldap->getConfiguration()->setAdminPassword($password);
         }
         try {
             $adldap->authenticate($username, $password);
             $user = User::firstOrCreate(['username' => $username]);
             $ldapUser = $adldap->users()->find($username);
             if ($ldapUser instanceof \Adldap\Models\User) {
                 $user->name = $ldapUser->getDisplayName();
                 $user->email = $ldapUser->getEmail();
                 $user->save();
                 Auth::login($user);
                 $this->alert('success', 'You are now logged in.', true);
                 return redirect($returnTo);
             }
         } catch (\Adldap\Exceptions\AdldapException $ex) {
             // Invalid credentials.
         }
     }
     // If we're still here, authentication has failed.
     $this->alert('warning', 'Athentication failed.');
     return redirect()->back()->withInput();
 }
开发者ID:samwilson,项目名称:asset-manager,代码行数:39,代码来源:UsersController.php


注:本文中的App\Model\User::firstOrCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。