Why doesn't the laravel eloquent model have an identifier after saving it?

I have an account model. I define and save it as follows:

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

dd($account->id) // null

Why is the account ID not updated? I am using autoincremental id field. I see a record in the database.

+4
source share
1 answer

You must set your primary key in your model.

Try pasting this into your model:

protected $primaryKey = "id";
+1
source

All Articles