Ande Caleb
Ande Caleb

Reputation: 1204

Creating default Object from empty value error

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;

Upvotes: 0

Views: 192

Answers (3)

Filip Koblański
Filip Koblański

Reputation: 9988

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); 

Upvotes: 0

Himanshu Raval
Himanshu Raval

Reputation: 811

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);

Upvotes: 1

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40899

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.

Upvotes: 0

Related Questions