本文整理汇总了PHP中app\Profile::whereUid方法的典型用法代码示例。如果您正苦于以下问题:PHP Profile::whereUid方法的具体用法?PHP Profile::whereUid怎么用?PHP Profile::whereUid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Profile
的用法示例。
在下文中一共展示了Profile::whereUid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginCallback
public function loginCallback()
{
$fb = new Facebook(['app_id' => '709854915792963', 'app_secret' => '74e61a2eaf730835d8b4b39ec3aede8e', 'default_graph_version' => 'v2.2']);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
// Logged in!
$access_token = (string) $accessToken;
// Now you can redirect to another page and use the
// access token from $_SESSION['facebook_access_token']
}
$response = $fb->get('/me?fields=id,name,email', $access_token);
$me = $response->getGraphUser();
$uid = $me['id'];
//return $uid;
if ($uid == 0) {
return Redirect::to('/')->with('message', 'There was an error');
}
//return $user;
$profile = App\Profile::whereUid($uid)->first();
//if user does not exist create user
if (empty($profile)) {
$user = new App\User();
$existinguser = App\User::whereemail($me['email'])->first();
if (empty($existinguser)) {
$user->name = $me['name'];
$user->email = $me['email'];
//$user->uid=$uid;
$user->save();
}
$profile = new App\Profile();
$profile->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large';
$user->email = $me['email'];
$profile->uid = $uid;
$profile->username = $me['name'];
$profile = $user->profiles()->save($profile);
}
//else only update his access token
$profile->access_token = $access_token;
$profile->save();
$user = $profile->users;
//login the user
Auth::login($user);
return Redirect::to('/dashboard');
}
示例2: Facebook
$facebook = new Facebook(Config::get('facebook'));
$params = array('redirect_uri' => url('/login/fb/callback'), 'scope' => 'email');
return Redirect::to($facebook->getLoginUrl($params));
});
Route::get('login/fb/callback', function () {
$code = \Illuminate\Support\Facades\Input::get('code');
if (strlen($code) == 0) {
return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');
}
$facebook = new Facebook(Config::get('facebook'));
$uid = $facebook->getUser();
if ($uid == 0) {
return Redirect::to('/')->with('message', 'There was an error');
}
$me = $facebook->api('/me?fields=id,name,email,picture');
$profile = Profile::whereUid($uid)->first();
if (empty($profile)) {
$user = new User();
$user->name = $me['name'];
$user->email = $me['email'];
$user->photo = $me['picture']['data']['url'];
$user->save();
$profile = new Profile();
$profile->uid = $uid;
$profile->username = $me['email'];
$profile = $user->profiles()->save($profile);
}
$profile->access_token = $facebook->getAccessToken();
$profile->save();
Auth::login($profile->user);
return redirect('/');