ErrorException(E_ERROR)尝试获取非对象的属性“生日”

时间:2018-06-11 10:37:33

标签: laravel

public function profile_settings()
{
    $student_information = Auth::user()->personal_information;
    return view('StudentViews.profile_settings' , compact('student_information'));
}

public function save_profile_information(Request $request)
{
    $flag = Auth::user()->personal_information;

    if ($flag != "") {
        $PersonalInformation                    =       Auth::user()->personal_information;
        $PersonalInformation->first_name        =       $request->first_name;
        $PersonalInformation->last_name         =       $request->last_name;
        $PersonalInformation->birthday          =       $request->birthday;
        $PersonalInformation->email             =       Auth::user()->email;
        $PersonalInformation->gender            =       Auth::user()->gender;
        $PersonalInformation->occupation        =       Auth::user()->occupation;
        $PersonalInformation->phone             =       $request->phone;
        $PersonalInformation->website           =       $request->website;
        $PersonalInformation->country           =       $request->country;
        $PersonalInformation->province          =       $request->province;
        $PersonalInformation->city              =       $request->city;
        $PersonalInformation->description       =       $request->description;
        $PersonalInformation->birthplace        =       $request->birthplace;
        $PersonalInformation->marital_status    =       $request->marital_status;
        $PersonalInformation->facebook          =       $request->facebook;
        $PersonalInformation->twitter           =       $request->twitter;
        $PersonalInformation->linkedin          =       $request->linkedin;
        $PersonalInformation->google_plus       =       $request->google_plus;

        $PersonalInformation->save();

        $user                                   =       Auth::user();
        $user->first_name                       =       $request->first_name;
        $user->last_name                        =       $request->last_name;
        $user->phone                            =       $request->phone;

        $user->save();
    }
    else {
        PersonalInformation::create([
            'user_id'           =>       Auth::user()->id,
            'first_name'        =>       $request->first_name,
            'last_name'         =>       $request->last_name,
            'birthday'          =>       $request->birthday,
            'email'             =>       Auth::user()->email,
            'phone'             =>       $request->phone,
            'country'           =>       $request->country,
            'province'          =>       $request->province,
            'city'              =>       $request->city,
            'description'       =>       $request->description,
            'gender'            =>       Auth::user()->gender,
            'occupation'        =>       Auth::user()->occupation,
            'website'           =>       $request->website,
            'birthplace'        =>       $request->birthplace,
            'marital_status'    =>       $request->marital_status,
            'facebook'          =>       $request->facebook,
            'twitter'           =>       $request->twitter,
            'linkedin'          =>       $request->linkedin,
            'google_plus'       =>       $request->google_plus,
        ]);
    }
}

2 个答案:

答案 0 :(得分:0)

使用is_object()功能进行检查。如果它是对象,则返回 TRUE 。 并且检查值为null或为空。

if (( $student_information != null) && (is_object($student_information))) {
    // code here
    // print any property here
}

然后错误将被修复。如果您打印的属性不包含值,则会显示如下错误。

答案 1 :(得分:0)

ViewController

它会给你一个错误,因为它没有值,所以用前一行替换刀片页面中的值,希望它能正常工作。