本文整理汇总了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();
}