0

down vote i am getting the same error but this is my approah $rval = '4q34ipuipfpaidapdfadup'//a random number...

  $details = Company::with('User')->where('email', Input::get('qpass'))->first();

  $u = $details['user'];
  $u->reset_pass = $rval;     //then save to the database...
  $u->save();

i get an error saying " creating default object from empty value ", at this line $u->reset_pass = $rval; and when i broke the model down into seperate entities i still got the same error at that same line... i need assistance.. thanks.

  $rval = '4q34ipuipfpaidapdfadup'//a random number... 

  $details = Company::where('email', Input::get('qpass'))->first();
  $u = User::find($details->user_id)->get(); 
  $u->reset_pass = $rval;     //then save to the database...
  $u->save();

and i still get that error at this point ($u->reset_pass = $rval;

1
  • Can you print and post your $u value? Commented Jun 10, 2016 at 7:32

3 Answers 3

1

try using

  $u = new User();
  $u = $u->find($details->user_id)->first(); 
  $u->reset_pass = $rval;     //then save to the database...
  $u->save();

also check if your user object is not empty by var_dump($u);

Sign up to request clarification or add additional context in comments.

2 Comments

This: find($details->user_id)->first() will fail.
i was thinking the same thing, but this never crossed my mind. you initialize the User object, and you assign it a different user on the second line. from the second line it might produce the same result as i was getting.
0

This error is returned when you try to write to an object property on an non-existent object.

Your $u variable is empty, that's why you're getting this error. Make sure that you fetch user correctly first - you can try dd($u); and see what it returns.

1 Comment

i did that and after dumping the output using dd($u) it returned a user object which was what i needed but now i did not understand the error, thats why i tried it in both ways.
0

This: $u = User::find($details->user_id)->get(); doesn't make sens. Yopu don't need to using get method. If you use find you will get the model so live it like this:

$u = User::find($details->user_id); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.