Get Last Inserted ID in a Model?
icangku opened this issue · 4 comments
icangku commented
How to get last inserted id ?
robkerry commented
I had the same question @webpatser :)
I've tried the standard method of requesting $model->id
after a $model->save()
, which returns 0
and I've tried setting the UUID as a variable $uuid = Uuid::generate(4)->string;
but the UUID saved to the database table is different to the $uuid
variable.
seth-shi commented
I found the answer.It was thought that there were three places in the Model::save method to determine whether it was self-increasing or not.
protected $primaryKey = 'uuid';
protected $keyType = 'string';
// Must be set Because Model::save uses this to determine whether it's self-increasing or not.
public $incrementing = false;
icangku commented
It does work! Thanks man!
vahidalvandi commented
work fine !