mardi 6 juin 2017

Laravel attempt to assign property of non-object

I want to allow user to update their profile created on a page however I get an error message saying that i am trying to attempt to assign property of non-object:

enter image description here

But user and twitter do have a value.

In a database field is called twitter_personal and of course id is a id.

Controller:

function updateProfile(Request $request) {
    $user = Auth::id();
    $twitter = $request->input('twitter');
    $user->twitter_personal = $twitter;
    $user->save();
    if($user->save()) {
    $message = 'Success';
    }else{
    $message = 'Error';
    }
   return redirect()->back()->withInput()->with('message', $message);

}

Form:

            <form class="form-horizontal" role="form" method="POST" action="">
                
                <div class="form-group">
                    <label for="twitter" class="col-md-4 control-label">Twitter</label>
                <div class="col-md-6">
                <input id="twitter" type="text" class="form-control" name="twitter">
                @if ($errors->has('url'))
                <span class="help-block">
                    <strong></strong>
                </span>
                @endif
        </div>
    </div>

So here's the question, how can I solve it? and is there a better way of doing it? if so please provide an example!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire