本文整理汇总了PHP中Social::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Social::where方法的具体用法?PHP Social::where怎么用?PHP Social::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Social
的用法示例。
在下文中一共展示了Social::where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Callback
/**
* Obtain the user information from the social media site.
*
* @return Response
*/
public function Callback($provider)
{
$user = Socialite::driver($provider)->user();
$socialUser = null;
//Check is this email present
$userCheck = User::where('email', '=', $user->email)->first();
if (!empty($userCheck)) {
$socialUser = $userCheck;
} else {
$sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
if (empty($sameSocialId)) {
//There is no combination of this social id and provider, so create new one
$name = explode(' ', $user->name);
$data = ['first_name' => $name[0], 'last_name' => $name[1], 'email' => $email];
$this->userRepository->SocialRegister($newSocialUser);
$socialData['social_id'] = $user->id;
$socialData['provider'] = $provider;
$socialRepository->saveSocial($socialData);
$role = Role::whereName('user')->first();
$newSocialUser->assignRole($role);
$socialUser = $newSocialUser;
} else {
//Load this existing social user
$socialUser = $sameSocialId->user;
}
}
$this->auth->login($socialUser, true);
if ($this->auth->user()->hasRole('user')) {
$this->checkFutureList();
return redirect('check');
}
if ($this->auth->user()->hasRole('administrator')) {
return redirect('adminHome');
}
}
示例2: getSocialHandle
public function getSocialHandle($provider)
{
$user = Socialite::with($provider)->user();
$socialUser = null;
//Check is this email present
$userCheck = User::where('email', '=', $user->email)->first();
if (!empty($userCheck)) {
$socialUser = $userCheck;
} else {
$sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
if (empty($sameSocialId)) {
//There is no combination of this social id and provider, so create new one
$newSocialUser = new User();
$newSocialUser->email = $user->email;
$name = explode(' ', $user->name);
$newSocialUser->first_name = $name[0];
$newSocialUser->last_name = $name[1];
$newSocialUser->save();
$socialData = new Social();
$socialData->social_id = $user->id;
$socialData->provider = $provider;
$newSocialUser->social()->save($socialData);
// Add role
$role = Role::whereName('user')->first();
$newSocialUser->assignRole($role);
$socialUser = $newSocialUser;
} else {
//Load this existing social user
$socialUser = $sameSocialId->user;
}
}
$this->auth->login($socialUser, true);
if ($this->auth->user()->hasRole('user')) {
return redirect()->route('/');
}
if ($this->auth->user()->hasRole('administrator')) {
return redirect()->route('/backoffice');
}
return \App::abort(500);
}