Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why laravel eloquent model does not have an id after it is saved?

I have an account model. I define & save it following way:

$account = new Account();
$account->email = $request->get('email');
$account->name  = $request->get('name');
$account->save();

dd($account->id) // null

Why account id is not updated? I use autoincremental id field. I see record in the database.

like image 768
avasin Avatar asked May 31 '15 17:05

avasin


1 Answers

You should set your primary key on your model.

Try to insert this on your model:

protected $primaryKey = "id";
like image 55
brunohdaniel Avatar answered Sep 28 '22 00:09

brunohdaniel