本文整理匯總了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);
}
示例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();
}