Properties 如何使用Laravel Oauth2检查属性是否存在(FB auth)

Properties 如何使用Laravel Oauth2检查属性是否存在(FB auth),properties,laravel,laravel-4,facebook-authentication,Properties,Laravel,Laravel 4,Facebook Authentication,我在Laravel中有一个Facebook登录的身份验证系统,当具有所有属性的用户登录时,该系统可以正常工作,但当用户没有填写其中一个属性时,它会抛出一个错误(例如): 未定义的属性:stdClass::$bio 以下是相关代码: Facebook.php: public function get_user_info(Token_Access $token) { $url = 'https://graph.facebook.com/me?'.http_build_quer

我在Laravel中有一个Facebook登录的身份验证系统,当具有所有属性的用户登录时,该系统可以正常工作,但当用户没有填写其中一个属性时,它会抛出一个错误(例如):

未定义的属性:stdClass::$bio

以下是相关代码:

Facebook.php:

public function get_user_info(Token_Access $token)
    {
        $url = 'https://graph.facebook.com/me?'.http_build_query(array(
            'access_token' => $token->access_token,
        ));

        $user = json_decode(file_get_contents($url));

        // Create a response from the request
        return array(
            'uid' => $user->id,
            'nickname' => $user->username,
            'name' => $user->name,
            'first_name' => $user->first_name,
            'last_name' => $user->last_name,
            'gender' => $user->gender,
            'email' => $user->email,
            'birthday' => $user->birthday,
            'location' => $user->location->name,
            'description' => $user->bio, //the line giving trouble for a user
            'friends'  => 'https://graph.facebook.com/me/friends?fields=id&access_token='.$token->access_token,
            'image' => 'https://graph.facebook.com/me/picture?width=200&height=200&access_token='.$token->access_token,
            'urls' => array(
            'Facebook' => $user->link,
            ),
        );
    }
Oauth2Controller.php:

if(is_null($check)) {

                  $fan = new Fan;

                  $fan->fbid = $user['uid'];
                  $fan->email = $user['email'];
                  $fan->first_name = $user['first_name'];
                  $fan->last_name = $user['last_name'];
                  $fan->gender = $user['gender'];
                  $fan->birthday = $user['birthday'];
                  $fan->age = $age;
                  $fan->city = $city;
                  $fan->state = $state_abbrev;
                  $fan->image = $user['image'];
                  $fan->friend_ids_url = $user['friends'];
                  $fan->friend_ids_unpacked = $friend_ids;

                  $fan->save();

                  $new = Fan::where('fbid', '=', $user['uid'])->first();

                  Auth::login($new);
                  return Redirect::to('fans/home');

                }
如何检查用户的配置文件中是否包含这些字段,以便不会抛出此错误?多谢各位

你能做到吗

 'description' => (isset($user->bio) ? $user->bio : NULL)