How to get last inserted id through save() method in laravel

后端 未结 6 1722
醉酒成梦
醉酒成梦 2021-01-22 03:37

I know to get the last id I can use insertGetId() but I want to know how can I get the last inserted id through save() method.

order =          


        
6条回答
  •  悲哀的现实
    2021-01-22 04:07

    In case of you did overwride the name of primary key in the model as in next case:

    protected $primaryKey = 'your_table_id_name';
    

    use:

    $id = $your_variable_save->your_table_id_name
    

    if not:

    $id = $your_variable_save->id
    

提交回复
热议问题